Consent mode is a reliable and easy way to ensure no cookies are set by Google scripts before user consent, when they are implemented using Google Tag Manager or gtag. While implementation is very simple, it can be difficult to tell if you got it right and things are as they should be.
First off, it's important to note that only the following tags in Google Tag Manager support Advanced consent mode:
To determine if consent mode is properly implemented, you can check three things:
- The Consent tab of the Preview in Google Tag Manager.
- The consent mode default settings registered in Google Tag Manager.
- Values registered in the dataLayer.
We will go through these checks which help you determine if consent mode is implemented correctly and is working as intended.
We assume you've added the consent mode script before the Google Tag Manager script as instructed in our guide.
Checking your consent mode settings in the Cookiebot Admin
You can check whether consent mode is enabled and correctly configured in the Cookiebot Admin.
To learn more about this, check out our Consent Mode Checker guide.
Checking the preview in Google Tag Manager
You can also inspect the preview to confirm that Consent is enabled, and if you're on version 2.
Start the preview and take the following steps:
- Select "Consent"
- Select the "Consent" tab
- Ensure that the "On-page Defaults" are set and that they include the two new parameters;
ad_personalization
andad_user_data
.
Checking the consent mode settings
When a page loads prior consent, the consent mode settings should be correctly registered in Google Tag Manager.
If you've implemented Cookiebot using the Cookiebot CMP tag, the default settings won't be pushed to the dataLayer, they will be registered internally in Google Tag Manager, so merely inspecting the dataLayer won't work if you implement Cookiebot CMP via our template tag in Google Tag Manager.
Here is a script that you can run in the console of your browser (typically accessible by pressing F12 in most browsers) which allows you to check what consent settings are registered in Google Tag Manager:
(() => { l = s => s == undefined ? "" : s ? "granted" : "denied"; c = s => s == "granted" ? "color: #0C0": "color: #C00"; if (!window["google_tag_data"]) { console.warn("No Consent Mode data found"); return; } var g = "ics" in google_tag_data ? google_tag_data.ics.entries : null,
i = "", t = "%c" + "Consent Mode settings:",
u = "";
console.log(t, "font-size: 1rem"); for (var a in g) { i = l(g[a]['default']); u = l(g[a]['update']); if (i == "" && u == "") continue; t = ("\t" + a + ":" + (i != "" ? "\n\t\tDefault: %c" + i : "%c") + "%c" + (u != "" ? "\n\t\tUpdate: %c" + u : "%c")); console.log(t, i != "" ? c(i) : "", "", u != "" ? c(u) : "", ""); } if (i == "") console.log("No default Consent settings found"); })()
If you've added the consent mode script inline or via our WordPress plugin, you should also see these settings in the dataLayer.
Checking the dataLayer
Checking the contents of the dataLayer can be done by simply executing the command dataLayer
in the console, or using this script to make it a bit easier to read:
(function(w, d, t) { for (i of w[d]) t += JSON.stringify(i).replaceAll(/\"\d{1,}\":/g, "") + "\n"; console.log(t); })(window, "dataLayer", "")
The output should look similar to this:
{"consent","default",{"ad_storage":"denied","analytics_storage":"denied","wait_for_update":500}}
{"set","ads_data_redaction",true}
{"gtm.start":1608107133821,"event":"gtm.js","gtm.uniqueEventId":2}
{"event":"gtm.dom","gtm.uniqueEventId":3}
{"event":"gtm.load","gtm.uniqueEventId":5}
After consent has been given for all types of cookies, the dataLayer will contain both the initial, and updated consent mode settings:
{"consent","default",{"ad_storage":"denied","analytics_storage":"denied","wait_for_update":500}}
{"set","ads_data_redaction",true}
{"gtm.start":1608106162221,"event":"gtm.js","gtm.uniqueEventId":2}
{"event":"cookie_consent_preferences","gtm.uniqueEventId":3}
{"event":"cookie_consent_statistics","gtm.uniqueEventId":4}
{"event":"cookie_consent_marketing","gtm.uniqueEventId":5}
{"gtm.start":1608106162636,"event":"gtm.js","gtm.uniqueEventId":7}
{"event":"gtm.dom","gtm.uniqueEventId":9}
{"event":"gtm.load","gtm.uniqueEventId":11}
{"set","developer_id.dMWZhNz",true}
{"consent","update",{"ad_storage":"granted","analytics_storage":"granted"}}
{"set","ads_data_redaction",false}
Comments
1 comment
Need help with your Google Consent Mode setup from a Cookiebot partner? Check our dedicated Consent Mode page for scenario's or a check by the CookieInfo team :-) https://www.cookieinfo.net/en/upgrade-google-consent-mode-v2/
Please sign in to leave a comment.