Skip to content

Instantly share code, notes, and snippets.

@mindbreaker
Created April 18, 2024 10:48
Show Gist options
  • Save mindbreaker/4a8de6341d38e1090e65238592508fac to your computer and use it in GitHub Desktop.
Save mindbreaker/4a8de6341d38e1090e65238592508fac to your computer and use it in GitHub Desktop.
Cookie Bot integration with GTM only loads statistics or marketing
<!-- Google Consent Mode -->
<script data-cookieconsent="ignore">
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments)
}
gtag("consent", "default", {
ad_personalization: "denied",
ad_storage: "denied",
ad_user_data: "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-->
<!-- Cookiebot CMP-->
<script
id="Cookiebot"
src="https://consent.cookiebot.com/uc.js"
data-cbid=""
data-blockingmode="auto"
type="text/javascript"
data-consentmode-defaults="disabled"
></script>
<!-- End Cookiebot CMP -->
<script type="text/javascript">
window.addEventListener('CookiebotOnAccept', function (e) {
if (Cookiebot.consent.marketing || Cookiebot.consent.statistics)
{
(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-');
}
}, false);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment