Complianz Privacy Suite

Adding Global site tag (gtag.js) with Granular Consent

Aert Hulsebos

Aert Hulsebos

Categories

Popular articles

Upgrade to Google Analytics 4

If you want to upgrade to Google Analytics 4 you will need to upgrade your tracking code. If you have implemented Analytics with Complianz, please

Read More

TCF for WordPress

The Transparency Consent Framework (TCF) is an initiative by IAB Europe and IAB Tech Lab to provide a platform for vendors, publishers, and consent management

Read More

TCF V2.0 release (Update)

Update: Released on October 5th 2020 Since August 15th the Transparency and Consent Framework V2.0 from IAB Europe or TCF V2 has been adapted by

Read More
Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

In the near future Complianz will switch to gtag.js, but in the meantime; here is how to add gtag.js, while controlling consent granularly between script tags. For Tag Manager, please follow this link.

This article will consist of three steps.

  1. Configuring the wizard
  2. Adjusting gtag.js for consent – This can also be used for Google Analytics 4
  3. Adding it to your website

1. Configuring the wizard

In the wizard, under Cookies – Statistics, you will need to choose between the following answers:

  • Yes, Anonymous – Choose this if you’re in the EU, do not target Germany or Austria, and have configured Analytics for GDPR. This answer will set Google Analytics before consent.
  • Yes, and the personal data is available to us – Choose this answer if the above doesn’t apply. This answer will set Google Analytics when the category “Statistics” has been consented to.

2. Adjusting gtag.js for consent

A gtag.js can be downloaded and appended to with other tags;

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async type="text/javascript" class="cmplz-native" src="https://www.googletagmanager.com/gtag/js?id=UA-68010-1"></script>
<script type="text/plain" class="cmplz-stats">
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'UA-680410-1'); // Google Analytics - Analytics Category or 
  gtag('config', 'G-680410-1'); // Google Analytics - 4 Measurement ID
</script>
<script type="text/plain" class="cmplz-script">
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());
  gtag('config', 'AW-680410-2'); // Remarketing for Google Ads - Marketing Category
</script>

The additions are as followed;

For each category we choose which part of the script can be fired, and what to adjust:

<script class="type/javascript" class="cmplz-native"</script> // Functional
<script class="type/plain" class="cmplz-stats"</script> // Statistics
<script class="type/plain" class="cmplz-script"</script> // Marketing

This is also possible with async, but deferring these scripts should be done with care, as they are dependent on each other. Testing this cross-browser is advised, because deferred script might fall back to async in some situations, creating false positives.

3. Adding it to your website

This is a personal preference, but Google states adding this between yourtags on your website. This is either done in your header.php or with a plugin like Header Footer Code Manager. You can use above code to start, and append and adjust where necessary.

Recent articles

Subscribe