Repository navigation
Clear the Google Analytics session cookie left after withdrawing consent - #26
Merged
Merged
Conversation
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
approved these changes
Nov 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_cookieslist; nothing changes for visitors who accept.Files
assets/cookie-notice/frontconsent-cookie-notice.js(+.min.jsrebuilt): one condition ininit(),=== '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
_gaand_ga_<ID>appear._ga*cookies left (with 1.0.2,_ga_<ID>remained).Checks
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