Cookieless Google Analytics v4 still generates _ga cookie

Viewed 389

I am trying to use the cookie-less Google Analytics implementation, so that our website can track visits before users accept cookies (switching to the standard version once they do), as per the Google Analytics documentation.

I'm using the technique described in this tutorial: https://medium.com/swlh/how-to-use-google-tag-manager-and-google-analytics-without-cookies-7d041c73cc76

I use the following code (simplified and stripped of irrelevant other scripts for the purpose of this post)

window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-xxxxxxxx', {
    send_page_view: true,
    client_storage: 'none',
    client_id: '<key-from-local-storage>',
});

Everything seems to work using this method - until I look into the site cookies in inspector. Regardless of the client_storage settings, a "_ga" cookie still gets generated.

When I use the standard cookie version of analytics (without the client_storage: "none") the same cookie gets generated, in exactly the same way.

I have also tried to use the Consent Mode for this, using the following code

gtag('consent', 'default', {
    analytics_storage: 'denied',
    ad_storage: 'denied'
});

later updating it to granted when user complies. This works in regards to blocking stuff, but also blocks ALL tracking from hapenning on Analytics - no results show up.

Does anybody know of any way to actually get the Analytics to NOT generate the _ga cookie, but still track visited URLs and basic data, that does not require cookies?

What does the cookie-less mode even do, when it generates the cookies just as before?

Am I missing something?


Edit: I have tried using the same cookieless update on the older Analytics version, that uses ga(...) functions, and the cookie disappeared as expected. So it seems only the v4 is not working as intended.

Code used (that works):

ga('create',    'UA-XXXXXXXX-X', {
    'storage': 'none',
    'clientId': window.localStorage.getItem(GA_LOCAL_STORAGE_KEY)
});
ga('send',      'pageview');
0 Answers
Related