Reputation: 123
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.
Upvotes: 11
Views: 8964
Reputation: 7396
gtag('consent', 'default', {
'ad_storage': 'denied',
'analytics_storage': 'denied'
});
Note that it must be called before any other commands that send measurement data.
https://developers.google.com/tag-platform/devguides/consent#set_consent_defaults
Upvotes: 17
Reputation: 236
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>
Upvotes: 4
Reputation: 166
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
Upvotes: 0