5
votes

I am looking for a way to disable the cookies set by Google Analytics. I found some infos in Google's devguides: https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#disabling_cookies

Here it says that I should add the following code:

ga('create', 'UA-XXXXXXXXX-X', {
  'storage': 'none'
});

But where exactly? I already tried to add it inside the tracking code:

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

  gtag('config', 'UA-XXXXXXXXX-X');


  ga('create', 'UA-XXXXXXXXX-X', {
  'storage': 'none'
});
</script>

I'm grateful for every clue.

3

3 Answers

2
votes

storage: 'none' is for analytics.js https://developers.google.com/analytics/devguides/collection/analyticsjs/cookies-user-id#disabling_cookies

For gtag.js, I think client_storage: 'none' is what you're looking for. It's referenced in a Medium article titled How to use Google Tag Manager and Google Analytics Without Cookies

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

  gtag('config', 'GA_MEASUREMENT_ID', {
       client_storage: 'none',
       client_id: CLIENT_ID,
  });

</script>
1
votes

Given you use gtag.js (based on your example you do):

window.dataLayer = window.dataLayer || [];

function gtag() {
    dataLayer.push(arguments);
}

gtag('js', new Date());
gtag('consent', 'default', {
    'ad_storage': 'denied',
    'analytics_storage': 'denied'
});
gtag('config', 'xxx');

Adjust tag behavior based on consent (beta)

0
votes

Two things, you have confused two versions, the ga create and gtag are different versions. Use the gtag one. Your code for this to work is below:

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

 window['ga-disable-UA-XXXXXXXXX-X'] = true;

 gtag('config', 'UA-XXXXXXXXX-X');

});
</script>

See reference here https://developers.google.com/analytics/devguides/collection/gtagjs/user-opt-out