Skip to content

Clear the Google Analytics session cookie left after withdrawing consent - #26

Merged
davidperezgar merged 1 commit into
mainfrom
fix/withdraw-ga-session-cookie
Nov 13, 2026
Merged

davidperezgar merged 1 commit into
mainfrom
fix/withdraw-ga-session-cookie

Conversation

@amulero

@amulero amulero commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Problem

After a visitor accepts cookies and then withdraws consent from the cookie icon, the banner comes back but Google Analytics' session cookie (_ga_<ID>, e.g. _ga_00PNZWJQGT) is still there. Reproduced on remolquesquinones.com with 1.0.2: after withdrawing, the reloaded page shows the banner with that cookie already set, before the visitor has decided anything.

Cause

On withdrawal FrontConsent deletes the tracking cookies and reloads the page. Google Analytics is still loaded on that page and rewrites its session cookie while the page unloads, after the purge has already run. On the reloaded page the visitor is undecided, and the page-load purge only ran for visitors who had rejected, so the cookie stayed until they pressed Reject.

Solution

The page-load purge now runs for anyone who has not accepted: rejected or undecided. Whatever Google Analytics rewrites during the reload is deleted as soon as the next page loads. Same frcn_cookie_notice_purge_cookies list; nothing changes for visitors who accept.

Files

  • assets/cookie-notice/frontconsent-cookie-notice.js (+ .min.js rebuilt): one condition in init(), === 'rejected' → !== 'accepted'.
  • tests/js/cookie-notice-purge.test.js: new test for an undecided visitor with a leftover _ga_* cookie (fails without the fix). The "accepting keeps tracking cookies" test now sets the cookie after page load, since a cookie present before acceptance is now purged by design.

How to test

  1. Incognito window, accept cookies: _ga and _ga_<ID> appear.
  2. Click the cookie icon to withdraw: the page reloads and the banner shows.
  3. DevTools → Application → Cookies: no _ga* cookies left (with 1.0.2, _ga_<ID> remained).

Checks

  • JS tests 41/41 ✅
  • composer lint ✅, composer phpstan ✅

Version

Like the other 1.1.0 PRs, this does not change the version or the changelog; they go in the release commit on main.

🤖 Generated with Claude Code

Withdrawing consent from the cookie icon purges tracking cookies and
reloads the page, but Google Analytics rewrites its _ga_<ID> session
cookie while the page unloads, after the purge has run. The reloaded
page then showed the banner with that cookie already set.

The page-load purge used to run only for a rejected visitor; it now runs
for anyone who has not accepted, which also covers the undecided state
right after a withdrawal.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@davidperezgar
davidperezgar merged commit 80c9210 into main Nov 13, 2026
9 of 21 checks passed
@davidperezgar
davidperezgar deleted the fix/withdraw-ga-session-cookie branch November 13, 2026 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants