What is Gtag (Global Site Tag) and do I need to use it?
In short, gtag.js is an easy way to embed all the Google tools and products in use on your website (like Google Analytics, Google Ads etc.) using a single tag.
If you are currently using Google Tag Manager (GTM) you do not need to use the gtag.js - you can continue to use GTM just as before (see our general GTM installation guide here: https://support.cookiebot.com/hc/en-us/articles/360003793854-Google-Tag-Manager-deployment).
How do I connect Gtag with Cookiebot?
As of September 3rd, 2020, Gtag supports Google Consent Mode. Cookiebot integrates to this API by Google, so that Gtag will automatically change behaviour in accordance with the end user's consent. All you need to do is to add an additional code snippet before your current Gtag snippet:
<script data-cookieconsent="ignore">
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>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-00000000-0" data-cookieconsent="ignore"></script>
<script data-cookieconsent="ignore">
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-00000000-0');
</script>
When you embed your Cookiebot tag on the site as well, Cookiebot will automatically connect with Gtag and signal the end user's consent through the Consent Mode API.
If you have enabled auto-blocking in Cookiebot, you also need to apply the tag attribute data-cookieconsent="ignore" to all three Gtag script tags as above.
You may change the values of ad_storage and analytics_storage to 'granted' and set ads_data_redaction to 'false' if you want to default to an opt-in before the end user has submitted consent, for example allowing for a default opt-in under CCPA.
Comments
1 comment
Google Ads also offers the possibility to add the conversion tracking into the Gtag code. Maybe the last example of mixed analytics and remarketing code may be updated to reflect the use of
Please sign in to leave a comment.