Skip to content

privacy(fix): delete GA's cookies when consent is withdrawn - #415

Merged
Ducksss merged 2 commits into
devfrom
claude/clear-ga-cookies-on-withdrawal
Jul 29, 2026
Merged

Ducksss merged 2 commits into
devfrom
claude/clear-ga-cookies-on-withdrawal

Conversation

@Ducksss

@Ducksss Ducksss commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Found by checking the live site, not the code. After resetting consent to a first-visit state, GA4 correctly did not load — but _ga and _ga_EMGRZ0H9R9 were still sitting in the browser from the earlier opt-in.

Withdrawal stopped collection and cleared our own pc_distinct_id, but never touched GA's cookies. So the visitor stayed identifiable to Google on their next visit. That's the cookie analogue of the stale-identifier bug fixed earlier — and under GDPR, withdrawal should remove identifiers, not just stop processing.

The fix

clearAnalyticsCookies() expires the _ga / _ga_* pair (plus legacy _gid / _gat*) on both denial paths: explicit withdrawal, and a GPC/DNT signal arriving after an opt-in.

Two details worth knowing:

  • A cookie can only be deleted by re-setting it with a matching domain and path, and script cannot read which domain a cookie came from — GA writes _ga on the registrable domain. So each plausible domain is tried; the misses are inert.
  • It runs before the existing reload, so the tag cannot re-set the cookies on its way out.

Testing

The spec seeds the cookies by hand rather than waiting for a real googletagmanager fetch — that keeps it deterministic instead of network-flaky, and it still pins the logic that matters.

It also asserts an unrelated cookie on the same domain survives, so the sweep can't quietly grow into deleting everything.

Docs

/privacy and contributing.mdx now say withdrawal deletes what the opt-in created, rather than implying it only stops collection.

Verification

lint clean · tsc clean · 379 int tests · consent + a11y e2e 20/20.

Found by checking the live site rather than the code: after resetting consent to
a first-visit state, GA4 correctly did not load — but `_ga` and
`_ga_EMGRZ0H9R9` were still sitting in the browser from the earlier opt-in.

Withdrawal stopped collection and cleared our own pc_distinct_id, but never
touched GA's cookies, so the visitor stayed identifiable to Google on their next
visit. That is the cookie analogue of the stale-identifier bug fixed earlier, and
under GDPR withdrawal should remove the identifiers rather than merely stop
processing.

clearAnalyticsCookies() expires the `_ga` / `_ga_*` pair (plus legacy `_gid` /
`_gat*`) on both denial paths: explicit withdrawal and a GPC/DNT signal arriving
after an opt-in. A cookie can only be removed by re-setting it with a matching
domain and path, and script cannot read which domain a cookie came from — GA
writes `_ga` on the registrable domain — so each plausible domain is tried and
the misses are inert. It runs before the existing reload so the tag cannot
re-set them on the way out.

The spec seeds the cookies by hand instead of waiting for a real
googletagmanager fetch, which keeps it deterministic rather than network-flaky,
and asserts an unrelated cookie on the same domain survives so the sweep cannot
grow into deleting everything.

/privacy and contributing.mdx now say withdrawal deletes rather than just stops.

Verified: lint clean, tsc clean, 379 int tests, consent + a11y e2e 20/20.

Co-Authored-By: Claude Opus 5 <[email protected]>
Copilot AI review requested due to automatic review settings July 29, 2026 16:59
@vercel

vercel Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
payload-components Ready Ready Preview, Comment Jul 29, 2026 5:18pm
payload-components-97bf Ready Ready Preview, Comment Jul 29, 2026 5:18pm

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Ducksss, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 40 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a8ba150d-6274-4ed4-beca-dab3cf1bf799

📥 Commits

Reviewing files that changed from the base of the PR and between aa3b6a9 and fdbd4d1.

📒 Files selected for processing (4)
  • content/docs/contributing.mdx
  • src/app/privacy/page.tsx
  • src/lib/consent.ts
  • tests/e2e/consent.e2e.spec.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

format:check gates on prettier as of #402/#408, and `pnpm lint` does not cover
it — so the privacy page landed unformatted. Reformatted.

The intro also still claimed "Nothing loads until you accept", which the
cookieless split made false: Vercel Analytics and Speed Insights load for
everyone. Now scoped to "nothing that stores anything on your device".

Co-Authored-By: Claude Opus 5 <[email protected]>

This branch was successfully deployed

2 active deployments
Preview – payload-components — fdbd4d11 Deployed Jul 29, 2026 by vercel[bot]
Preview – payload-components-97bf — fdbd4d11 Deployed Jul 29, 2026 by vercel[bot]
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