Google-Analytics cookies set before consent with EU Cookie Compliance “opt-in with categories” mode

Created on 7 July 2025, 5 days ago

Problem/Motivation

Google Analytics cookies are set and persist regardless of consent state (EU Cookie Compliance “Opt-in with categories”)

Steps to reproduce

Environment:
- Drupal: 10.4.1
- Module google_analytics: 4.0.3
- Module eu_cookie_compliance:8.x-1.27
- PHP: 8.3
- Browser(s): Chrome 125, Firefox 124 (same result)

# eu_cookie_compliance settings
mode: opt_in_with_categories
categories:
- google_analytics
allowed_cookies:
- google_analytics:_ga
- google_analytics:_ga*
- google_analytics:_gid
- google_analytics:_gat
- google_analytics:AMP_TOKEN
- google_analytics:_gac_*
- google_analytics:_dc_gtm_*
# google_analytics module
web_property_id: UA-XXXXXX-1 # or G-XXXXXXXX

Clear all cookies or open in a private window.

Visit the homepage.
Do not touch the cookie banner.
Open DevTools › Application › Cookies → observe _ga, _gid already set.
Click “Reject all” → cookies remain.
Reload the page → cookies still there.
Click “Save preferences” with all categories unchecked → cookies still remain.
Click “Accept all” → cookies remain (expected here).
Then click “Withdraw consent” → cookies still not removed.

Proposed resolution

i created locally a diff file with the changes that workd for me.

🐛 Bug report
Status

Active

Version

1.27

Component

Code

Created by

🇩🇪Germany eueco

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @eueco
  • 🇳🇿New Zealand atowl

    Hi @eueco

    Thanks for the very detailed report! I like how much information you supplied!!

    I feel however, that this is probably more to do with the google_analytics module? The EUCC module isn't responsible for cleaning up the analytics cookies left behind, and if we do, that's just for the analytics cookies, what about other sites cookies?

    We do provide notifiers inside the JS for other modules to hook into to see the state of categories accepted? maybe thats what you're after instead?

    Very happy to discuss this further if you think we need to look into it

    thanks!

Production build 0.71.5 2024