Info
Content

Working with Google Analytics

Important: The commands might be different depending on your CMP settings. See information in IAB TCF compliance here.

In order to block Google Analytics codes unless consent is given, you can simply change your Google Analytics code.

Note: Many Shop- and CMS-Systems offer Google Analytics plugins for easier integration. Usually these plugins cannot be customized. Hence we recommend to disable the plugin and integrate Google Analytics directly into your website (with below alignments to the analytics code).

Version with Google TagManager-Code (gat/gtag)

Your orginal code will look like this:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-1111111-01"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-1111111-01');
</script>

In order to block the code, all you need to do is to add a few characters in the first line (read more about blocking codes here). The new code will look like this:

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async class="cmplazyload" data-cmp-vendor="s26" data-cmp-src="https://www.googletagmanager.com/gtag/js?id=UA-1111111-01"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-1111111-01');
</script>

Version with Google Analytics-Code (ga/analytics)

Your original code will look like this:

<script type="text/javascript">		
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-11111111-1', 'mywebsite.de');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>

In order to block the code, all you need to do is to add a few lines. The new code will look like this:

<script type="text/plain" class="cmplazyload" data-cmp-vendor="s26">	
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-11111111-1', 'mywebsite.de');
ga('set', 'anonymizeIp', true);
ga('send', 'pageview');
</script>

How to disable Google Remarketing within Google Analytics code?

If you have Google Remarketing activated in your Google Analytics account, you might want your visitors to distinguish between enabling/disabling Google Analytics and (also) enabling/disabling Google Remarketing. In order to do this, please follow these steps:

  1. Ensure that Google Ads (vendor ID s1) is listed in your vendor list
  2. Apply the above stated changes to the Google Analytics codes
  3. Add the following lines to your Analytics code:

For Google TagManager Codes (gat/gtag)

Add the following code right before the gtatg('config,'...') command:

window.gatpadsallowed = false;
 __cmp('getVendorConsents',null,function (x,y)
       {
        if("customVendorConsents" in x && "s1" in x.customVendorConsents and x.customVendorConsents["s1"])
        {
         window.gatpadsallowed = true;
        }
       });
gtag('set', 'allow_ad_personalization_signals', window.gatpadsallowed);

For Google Analytics Codes (ga/analytics)

Add the following code right before the ga('send','...') command:

window.gatpadsallowed = false;
 __cmp('getVendorConsents',null,function (x,y)
       {
        if("customVendorConsents" in x && "s1" in x.customVendorConsents and x.customVendorConsents["s1"])
        {
         window.gatpadsallowed = true;
        }
       });

if(!window.gatpadsallowed)
{
 ga('require', 'displayfeatures');
 ga('set', 'allowAdFeatures', false);
}
Back to top