วิธีใช้ Consent Mode ผ่าน GTM(Google Tag Manager)
Consent Mode คืออะไร
Consent Mode คือ วิธีจัดการ consent (ความยินยอม) ของผู้ใช้ผ่าน GTM เพื่อกำหนดขอบข่ายหรีอจำกัดการทำงานบางอย่าง เช่น การบันทึก Cookie ของ GA4 โดย เราจะทำการกำหนดเงื่อนไขในการทำงานต่างๆ ของ Tag ผ่าน GTM
ขึ้นตอนการใช้งาน Consent Mode
การติดตั้งโดยใช้ Template
Install Templates
ดาวน์โหลดไฟล์ ที่นี่ Cookie Wow - Google consent mode Template
ไปที่ https://tagmanager.google.com/#/home และเลือกโปรเจ็กที่คุณต้องการติดตั้ง Google Consent Mode
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/1_dayhrl.png)
คลิกที่ Templates ที่อยู่ทางด้านซ้ายของ Panel
ด้านใน Tag Templates , คลิกที่ New
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/4_eqnvu9.png)
คลิกที่ three-dot button ที่อยู่บริเวณด้านขวาบน
เมื่อมี Dropdown menu เลือก Import
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/6_1cnp1h4.png)
เลือกไฟล์ที่เราต้องการใช้งานจากข้อ 1
กด Save เพื่อบันทึก
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/8_1dliyx6.png)
Create Triggers
ไปที่ https://tagmanager.google.com/#/home และเลือกโปรเจ็กที่คุณต้องการติดตั้ง Google Consent Mode
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/1_d10h85.png)
คลิกที่ Triggers บริเวณด้านซ้ายมือ
ด้านใน Triggers , คลิกที่ New
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/10_1pb8m9n.png)
คลิกที่ Choose a trigger type to begin setup
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/11_1rce9d.png)
เลือก Custom Event
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/12_1c05awg.png)
จากนั้นตั้งชื่อ Event name ว่า CookieWowConsentUpdated และเลือก This trigger fires on เป็น All Custom Events
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/13_1xyfbg8.png)
ตั้งชื่อ Trigger ว่า CookieWow Event และกด Save
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/14_ir7wsb.png)
ทำตามขั้นตอนที่ 3 และ 4 อีกครั้งเพื่อสร้าง Trigger สำหรับตั้งค่า default consent
เลือก Consent Initialization และเลือก This trigger fires on เป็น All Pages
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/17_8gvi2r.png)
ตั้งชื่อ Trigger ว่า Initialize - All Pages และ Save
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/18_1odjaa4.png)
Create Tags
ไปที่ https://tagmanager.google.com/#/home และเลือกโปรเจ็กที่คุณต้องการติดตั้ง Google Consent Mode
คลิกที่ Tags บริเวณด้านซ้ายมือ
ด้านใน Tags , คลิกที่ New
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/19_dx3qgx.png)
คลิกที่ Choose a tag type to begin setup ใต้ Tag Configuration
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/20_15i8lgz.png)
เลื่อนลงมาที่ Custom เลือก CookieWow-GCM
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/21_1insob0.png)
คลิกที่ Choose a trigger to make this tag fire ใต้ Triggering
เลือก CookieWow Event
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/22_nkbkw1.png)
กดเครื่องหมาย + เพื่อเพิ่ม Trigger
เลือก Initialization - All pages
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/23_uhoh1o.png)
ตั้งชื่อ Tags และกด Save เพื่อบันทึก
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/26_ua2nhm.png)
ตรวจสอบว่าสามารถใช้งานได้หรือไม่
ไปที่ https://tagmanager.google.com/#/home และเลือกโปรเจ็กที่คุณต้องการติดตั้ง Google Consent Mode
คลิกที่ปุ่ม Preview บริเวณด้านขวาบน จะมีหน้าต่าง Tag Assistant แสดงขึ้นมา
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/27_1brh18b.png)
ใส่ URL ที่ต้องการตรวจสอบและคลิก Connect
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/28_oez0wm.png)
จะมีหน้าต่างเว็บไซต์ที่ท่านต้องการตรวจสอบแสดงขึ้นมา
ในหน้าต่าง Tag Assistant คลิกที่ Initialization ด้านซ้ายมือ
ใต้ Consent Tab หากคุณยังไม่ได้ให้ความยินยอมผ่าน CookieWow Banner คุณจะเห็นค่าของ analytics_storage and ad_storage เป็น ‘denied’ และเมื่อเข้าไปยัง network ของ browser ของคุณ ใน network ข้อมูลที่ส่งไปยัง GA จะมี tag GA100
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/30_1m4l56k.png)
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/32_1ilewy.png)
หลังจากให้ความยินยอมผ่าน CookieWow Banner แล้ว analytics_storage และ ad_storage จะเป็น ‘granted’. และเมื่อเข้าไปยัง network ของ browser ของคุณ ใน network ข้อมูลที่ส่งไปยัง GA จะมี tag GA111
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/33_qvqbjz.png)
![](https://storage.crisp.chat/users/helpdesk/website/f1ac0320b192f000/34_rpe1u6.png)
การติดตั้งแบบ Manual
1. ใส่โค้ดด้านล่างร่วมกับการติดตั้งแบนเนอร์คุกกี้ของ Cookie Wow
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
console.log('test')
gtag('consent', 'default', {
'ad_storage': 'denied',
'analytics_storage': 'denied',
})
</script>
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','CONTAINER-CODE');</script>
<!-- End Google Tag Manager -->
<!-- Cookie Consent by https://www.cookiewow.com -->
<script type="text/javascript" src="https://staging.cookiecdn.com/cwc.js"></script>
<script id="cookieWow" type="text/javascript" src="https://staging.cookiecdn.com/configs/PrzdwtxKMDQNYGJk4DJ7gbcH" data-cwcid="PrzdwtxKMDQNYGJk4DJ7gbcH"></script>
<script type="text/javascript">
function cwcCookieWrapper() {
if (window?.cwcIsUserAccept === undefined) return
if (window.cwcIsUserAccept('analytics')) {
gtag('consent', 'update', {
'analytics_storage': 'granted'
})
}
if (window.cwcIsUserAccept('marketing')) {
gtag('consent', 'update', {
'ad_storage': 'granted'
})
}
}
cwcCookieWrapper()
</script>
สามารถดูข้อมูลการใช้ Consent Callback เพิ่มเติมได้ที่ https://app.crisp.chat/website/ee859ce6-e4d8-427d-9552-52ee58fe4b3e/helpdesk/articles/th/a5032fd7-1bdc-4288-9a8b-3bbaf70b6ac1/)
References
https://developers.google.com/tag-platform/devguides/consent
https://support.google.com/google-ads/answer/10000067
https://support.google.com/analytics/answer/9976101
อัปเดตเมื่อ: 06/02/2023
ขอบคุณ!