In google’s consent mode there are some parameters that need to be set. These parameters stand for shop visitors' consent on specific things such as personalized ads etc.
You need to create a piece of javascript code which will set these parameters according to the shop’s visitor cookie consent saved in “AllowedCookies” cookie.
Setup guide
- Fill your GA Measurement ID into the field above
- Add a new "External script" for the default "consent to track" behavior:
- Name it e.g. "📊 Google Analytics (default)"
- Set State to Enabled
- Script target set to Every page - Every user
- Set Script position to In Head Section
-
Script Cookie Tags
- Performance should be unchecked
- Analytics should be unchecked
- Marketing should be unchecked
- Click on the diskette icon to copy the script below and then paste it into the Code text box
<script>
var gaCode = 'TAG_ID';
var isMarketingAllowed = '{{ALLOWED_COOKIES_MARKETING}}' == '1' ? 'granted' : 'denied';
var isTrackingAllowed = '{{ALLOWED_COOKIES_TRACKING}}' == '1' ? 'granted' : 'denied';
var isPerfomranceAllowed = '{{ALLOWED_COOKIES_PERFORMANCE}}' == '1' ? 'granted' : 'denied';
function gtag() { dataLayer.push(arguments); }
function addScript(gaCode) {
var gtagScript = document.createElement('script');
gtagScript.async = true;
gtagScript.src = 'https://www.googletagmanager.com/gtag/js?id='+gaCode;
var firstScript = document.getElementsByTagName('script')[0];
firstScript.parentNode.insertBefore(gtagScript, firstScript);
}
function consentUpdate() {
gtag('consent', 'update', {
'ad_user_data': isTrackingAllowed,
'ad_personalization': isMarketingAllowed,
'ad_storage': isTrackingAllowed,
'analytics_storage': isTrackingAllowed,
});
}
addScript(gaCode);
window.dataLayer = window.dataLayer || [];
gtag('consent', 'default', {
'ad_user_data': 'denied',
'ad_personalization': 'denied',
'ad_storage': 'denied',
'analytics_storage': 'denied',
'wait_for_update': 500,
});
gtag('js', new Date());
gtag('config', gaCode);
</script>
Externí script #1 – Google Analytics (default)
- Add a new "External script" for advanced "consent to track" behavior:
- Name it e.g. "📊 Google Analytics (update)"
- Set State to Enabled
- Script target set to Every page - Every user
- Set Script position to Before Body End
-
Script Cookie Tags
- Performance should be unchecked
- Analytics should be checked
- Marketing should be checked
- Click on the diskette icon to copy the script below and then paste it into the Code text box
<script>
const cookiesBtn = document.body.contains(document.getElementById('accept-all-btn')) ? true : false;
if (cookiesBtn) {
document.getElementById('accept-all-btn').addEventListener("click", function(e) {
localStorage.setItem("consentGranted", "true");
});
} else {
consentUpdate();
}
</script>
Externí script #2 – Google Analytics (advanced)
In Google Analytics, these changes can take up to 48 hours to take effect.
In order for Google Analytics to verify that everything is set up correctly after this time, it is necessary for the website to record at least 1 visit during this time to reconcile with the use of cookies.
Consent Settings
It's crucial to differentiate between the "default" and "update" settings when implementing the gtag() function in your website's code. Incorrect usage could limit the functionality of Google services like Google Analytics 4 (GA4), Google Ads, and others.
Default Setting:
The gtag('consent', 'default', {...}); configuration is regionally dependent. In the European Economic Area (EEA), which includes EU countries plus Norway and others, the default status should be set to "denied" to comply with GDPR regulations. However, in countries not governed by GDPR, it might be permissible to set certain functionalities to "granted" without explicit user consent.
Update Setting:
On the other hand, gtag('consent', 'update', {...}); should be used to reflect the user's actual consent choices as indicated via the cookie consent bar. Since consent information doesn't persist across page loads, this update needs to be called on every page view within your site. Additionally, it should be invoked any time a user updates their consent preferences through the cookie consent bar.
This distinction is critical for maintaining both the functionality of Google's tools on your website and compliance with privacy regulations. The proper implementation ensures that user preferences are accurately captured and respected across your site, allowing for personalized experiences where permitted and safeguarding privacy where required.
Example of GA Consent v2 in unapproved form
Example of GA Consent v2 in approved form
Cookiebar and Google Consent Mode (v2)
The link between a cookie consent bar and Google Consent Mode is vital for balancing user privacy with the functionality of digital marketing tools. A cookie consent bar is a user interface element on websites that notifies visitors about the use of cookies and seeks their consent. When a user interacts with this consent bar to approve or deny the use of specific types of cookies, their preferences are recorded.
Google Consent Mode takes these user preferences into account by adjusting how Google's services, such as Google Ads and Google Analytics, handle cookies and data collection based on the consent given. This integration should ensure that websites can comply with privacy regulations like the GDPR while still gathering essential data for analytics and advertising purposes. Please note, that this integration is fully in your hands as everything what's done through external scripts.
Google Consent Mode v2 is an update to Google's framework designed to help websites manage user consents for cookies and data collection in compliance with privacy laws. It allows sites to adjust how Google's services, such as Analytics and Ads, behave based on the consent given by users, ensuring that data is collected and used responsibly. For implementation, in gtag.js, you integrate consent settings directly within the configuration code, specifying consent states for various services. In Google Tag Manager, you use the built-in consent management features to control when and how tags are fired based on user consent. These setups ensure that websites can continue to collect valuable insights and run marketing campaigns while respecting user privacy.
TIP
For specific code examples and detailed setup instructions, it's best to refer directly to Google's official documentation:
Google Consent mode reference link
Google Consent Mode partners (Solutions for other cookie bars) link
HIRE AN EXPERT
If you need further assistance, just Contact our Support team.
Comments
0 comments
Please sign in to leave a comment.