5 min JavaScript guide on implementing Consent Mode for your website:
Joseph Sian Gou Wei
Advertising Solutions Architect @ Google | Founder of Jubilant Media | Ex-Criteo, Ex-Liftoff | Ad Tech | Entrepreneur and an Overly Curious Learner.
Step 1: Fire a consent default event when the page first start to load:
// Define dataLayer and the gtag function.
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
// Set default consent to 'denied' as a placeholder
// Determine actual values based on your own requirements
gtag('consent', 'default', {
'ad_storage': 'denied',
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'analytics_storage': 'denied'
});
Step 2: Implement Banner in your website code (I won’t go into details about this here but here is an example ). Just make sure you have a front end banner and able to capture users' input on the permission.
Step 3: Fire update event when user updates the permission on Banner:
// Create variables for each permission based on users options in Banner
// Example: ad_storage_permission = "granted"
window.gtag('consent', 'update', {
ad_storage: ad_storage_permission,
analytics_storage: analytics_storage_permission,
ad_user_data: aad_user_permission,
ad_personalization: ad_personalization_permission
});