What is Google Consent Mode

Google Consent Mode is a new API from Google which makes it easy for websites to measure conversions and traffic in Google Ads and Google Analytics while being fully GDPR cookie Compliant.

With Google Consent Mode your website can still get data from Ads campaigns, attribute conversions, and measure website traffic even though users decline your use of cookies.

This is still in BETA version at Google.

Read about GCM API at Google Developers.

Preliminary implementation

Cookie Information will soon include Google Consent Mode as a default in all Cookie Information Implementations.

Because of the increasing interest in Google Consent Mode, we have developed a method so all clients can use it now. But as soon as we include Google Consent Mode as default you might have to remove some changes we ask you to make here.

We will inform you via email once this happens.

If you have previously set up our SDK in Google Tag Manager, you can go ahead and revert the SDK triggers for the Google Analytics tag & Adwords tags in that Google Consent Mode will handle the blocking part.

When can you use Google Consent Mode?

If you are using Google's new gtag script or Tag Manager, then you can use the new Consent Mode API.

The script looks as shown below:

<!-- Global site tag (gtag.js) - Google Analytics --> 
<script async src="https://www.googletagmanager.com/gtag/js?id=CONTAINER-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'CONTAINER-ID');
</script>

Prerequisites

It doesn't work with the old Google Analytics or Adwords script, so to enable Google Control Mode you might also need to update your Google Implementation.

How to implement Google Consent Mode

The below script is used to enable and set the initial configuration of the Consent Mode.

The script must be placed above the tag or GTM script that you already have on your website. The two parameters:

  • ad_storage
  • analytics_storage

Both parameters are both set to deny, so the analytics platform and the ads platform, will not set any cookies on the initial load but will be executed when consent is given.

<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
wait_for_update: 500,
});
gtag('set', 'ads_data_redaction', true);
</script>

How to use the Cookie Control SDK to trigger the Consent Mode on consent

The Consent Mode has two parameters to trigger their analytics- and ads-platform, which is considered either statistic or marketing. Therefore you need to use those two consent categories to enable them.

You can use the Cookie Control SDK for inline scripts, to fire the Consent Mode API on the right category, as illustrated below:

<script> 

window.addEventListener('CookieInformationConsentGiven', function (event) {
if (CookieInformation.getConsentGivenFor('cookie_cat_statistic')) {
gtag('consent', 'update', {'analytics_storage': 'granted'});
}
if (CookieInformation.getConsentGivenFor('cookie_cat_marketing')){
gtag('consent', 'update', {'analytics_storage': 'granted'});
}
}, false);

</script>

Example of a complete setup

<head>
<!-- Cookie Information Pop-up Script is required for the SDK -->
<script id="CookieConsent" src="https://policy.app.cookieinformation.com/uc.js" data-culture="EN" type="text/javascript"></script>

<!-- The initial config of Consent Mode -->
<script type="text/javascript">
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('consent', 'default', {
ad_storage: 'denied',
analytics_storage: 'denied',
wait_for_update: 500,
});
gtag('set', 'ads_data_redaction', true);
</script>

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=CONTAINER-ID"></script>
<script type="text/javascript">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'CONTAINER-ID');
</script>

</head>
<body>

<!-- SDK for inline script that triggers Consent Mode on user consent -->
<script>
window.addEventListener('CookieInformationConsentGiven', function (event) {
if (CookieInformation.getConsentGivenFor('cookie_cat_statistic')) {
gtag('consent', 'update', {'analytics_storage': 'granted'});
console.log('GTAG Consent');
}
if (CookieInformation.getConsentGivenFor('cookie_cat_marketing')){
gtag('consent', 'update', {'ad_storage': 'granted'});
}
}, false);
</script>
</body>
Did this answer your question?