Combine the use of Google Tag Manager with automated cookie blocking by Cookiebot to get the best of both worlds. Implementation is quick and easy and allows you to:
- Control tags and cookies based on the user's consent, using triggers and Consent Mode in Google Tag Manager AND
- Let Cookiebot automatically control all other cookies not set by Google Tag Manager, based on the consent given, typically cookies set by third party scripts that are embedded directly in your website.
To achieve this, make sure that the Cookiebot script is not executed by Google Tag Manager. So either remove the Cookiebot CMP tag, pause it, or remove the trigger assigned to it.
Furthermore, for optimal results:
- If you choose to use Google Consent Mode, ensure this script loads before the Google Tag Manager script does.
- Mark up the Google Consent Mode and Google Tag Manager script tags with:
data-cookieconsent="ignore"
This will ensure that these scripts can't unintentionally get blocked by the auto blocking feature. - Ensure that the following scripts are the first on the page to load, in this exact order:
- Google Consent Mode
- Google Tag Manager
- Cookiebot CMP (with automatic cookie blocking)
Here's an example of how this could look:
<!DOCTYPE html>
<html>
<head>
<title>Google Tag Manager & automatic cookie blocking</title>
<!-- Google Consent Mode -->
<script data-cookieconsent="ignore">
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments)
}
gtag("consent", "default", {
ad_storage: "denied",
analytics_storage: "denied",
functionality_storage: "denied",
personalization_storage: "denied",
security_storage: "granted",
wait_for_update: 500
});
gtag("set", "ads_data_redaction", true);
gtag("set", "url_passthrough", true);
</script>
<!-- End Google Consent Mode-->
<!-- Google Tag Manager -->
<script data-cookieconsent="ignore">
(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','GTM-XXXX');</script>
<!-- End Google Tag Manager -->
<!-- Cookiebot CMP-->
<script
id="Cookiebot"
src="https://consent.cookiebot.com/uc.js"
data-cbid="abcdef12-3456-7890-abcd-ef1234567890"
data-blockingmode="auto"
type="text/javascript"
></script>
<!-- End Cookiebot CMP -->
...
</head>
<body>
...
</body>
</html>
data-layer-name
attribute to the Cookiebot CMP script tag, with the new dataLayer name as its value.For example:
data-layer-name="gtmDataLayer"
.
Google Consent Mode
For tags that support built-in consent checks, like Google Ads Conversion Tracking and Remarketing, Floodlight, Google Analytics and Conversion Linker, we recommend using Google Consent Mode, which can be activated by inserting the following snippet before the Google Tag Manager script in your header:
<script data-cookieconsent="ignore"> window.dataLayer = window.dataLayer || []; function gtag() { dataLayer.push(arguments); } gtag("consent", "default", { ad_storage: "denied", analytics_storage: "denied", functionality_storage: "denied", personalization_storage: "denied", security_storage: "granted", wait_for_update: 500, }); gtag("set", "ads_data_redaction", true);
gtag("set", "url_passthrough", true); </script>
Furthermore, if you have renamed the dataLayer, ensure that you replace
window.dataLayer
with the actual name of the dataLayer. For example:
window.gtmDataLayer
= window.gtmDataLayer || [];
For all other cookie-setting tags in Google Tag Manager, implement Additional Consent Checks as described in our GTM deployment guide.
You can also make use of Consent triggers as described in Alternative methods for conditionally loading tags.
Disabling Consent Mode
It's important to note that regardless whether you implement the Consent Mode script, which sets the default permissions within Google Tag Manager, the Cookiebot script will always pass updated Consent Mode data when it has established a visitor's consent choices.
If you for any reason prefer not making use of Consent Mode, you have to option to prevent Cookiebot from sending Consent Mode signals to Google Tag Manager.
Please see Disabling Consent Mode for instructions.
You may also implement the use of Google Tag Manager with manual blocking and implementation of prior consent for any remaining elements outside your tag manager. Use the script for manual cookie blocking and follow our guide here for setting up Google Tag Manager implementation
Comments
0 comments
Please sign in to leave a comment.