Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disabling cookies in Google Analytics - gtag.js

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.

like image 595
Khaleen Avatar asked Nov 11 '19 12:11

Khaleen


People also ask

Can Google Analytics work without cookies?

Can Google Analytics work without cookies? Yes, using Google Consent Mode can make your website run Google Analytics based on the consent state of your end-users.

Will GA4 work without cookies?

GA4 is promoted as privacy-centric and has been designed to work with or without cookies. By leveraging machine learning and statistical modeling, GA4 can fill in data gaps as the world becomes less and less dependent on cookies.

Should I use GTAG or GTM?

If you have to make a choice between Gtag and GTM, my recommendation would be to go with GTM. Once your developer has implemented the Google Tag Manager container everything can be done within the platform, you won't need to hardcode anything in the source.


1 Answers

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

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');

https://developers.google.com/tag-platform/devguides/consent#set_consent_defaults

like image 53
Artur Beljajev Avatar answered Oct 23 '22 19:10

Artur Beljajev