orestbida / cookieconsent

:cookie: Simple cross-browser cookie-consent plugin written in vanilla js
https://playground.cookieconsent.orestbida.com/
MIT License
4k stars 410 forks source link

Google Analytics `_ga_XXXXXXXXXX` cookie is recreated after autoclear #249

Closed bobapple closed 2 years ago

bobapple commented 2 years ago

I'm using Google Analytics 4 with autoclear_cookies: true. GA4 creates two cookies: _ga and _ga_XXXXXXXXXX. It seems to me that autoclear correctly removes both cookies if the user revokes consent for the analytics cookiecategory. However, the _ga_XXXXXXXXXX is recreated after page reload. I believe it's being recreated because in some cases I can see the cookie disapear even without reloading the page.

How to reproduce:

0. Keep the browsers developer tools open at any time to see the changes 1. Accept all cookies

accept-all

2. Open cookie settings and remove consent for the analytics category 3. Save changes 4. Reload page

revoke-consent

Sample Config ```

Cookie Consent test

```
orestbida commented 2 years ago

Hi @bobapple.

In GA4, you must explicitly “tell” the gtag function to disable cookies/tracking when the user opts-out of a specific category, as shown in the demo example: https://github.com/orestbida/cookieconsent/blob/49fbcc9a1fbf3ddd25c0f0af6963ac26dc9a9c13/demo/demo_gtm/cookieconsent-init.js#L47-L56

bobapple commented 2 years ago

Thank you @orestbida! Totally missed that part in de documentation.