Skip to content

docs: expire stale ad click ids before sending conversions to the worker#8799

Open
pubkey wants to merge 2 commits into
masterfrom
claude/expire-stale-ad-click-id
Open

docs: expire stale ad click ids before sending conversions to the worker#8799
pubkey wants to merge 2 commits into
masterfrom
claude/expire-stale-ad-click-id

Conversation

@pubkey

@pubkey pubkey commented Jul 16, 2026

Copy link
Copy Markdown
Owner

This PR contains:

A BUGFIX (docs site conversion tracking — docs-src).

Describe the problem you have without this PR

storeAdClickId() (docs-src/src/theme/Root.tsx) saves the gclid/gbraid/wbraid from the landing URL into localStorage under click_id, and getStoredAdClickId() (docs-src/src/components/trigger-event.tsx) reads it back for every tracking event to attribute conversions sent to the offline-conversion worker.

The stored id never expired. So once a visitor arrives from an ad, getStoredAdClickId() keeps returning that same click id indefinitely — on every later visit, including organic return visits weeks or months later. Every one of those events is then posted to /api/google-ads attributed to the old click. Two concrete problems:

  • Google Ads rejects the upload with "This click is too old" once the click is past the conversion window (observed on the live offline-conversion upload).
  • Even inside the window, crediting a much-later visit to a long-past ad click is mis-attribution — the worker keeps uploading conversions against a click the visit had nothing to do with.

The fix

Ignore — and clear — a stored click id once it is older than 90 days (Google Ads' maximum click-through conversion window). After that a click can never be legitimately imported anyway, so getStoredAdClickId() returns null and removes the stale entry. The client then only ever calls the worker with a click id that can still be attributed. Also hardens against a missing/invalid timestamp.

Behaviour is unchanged for normal (fresh) ad clicks; only stale ids are dropped.

Todos

  • Tests — the change lives in docs-src (Docusaurus site tracking code), which has no unit-test harness in this repo (the test/ suite covers the library, not the docs site). The fix is a small, self-contained localStorage-age guard; happy to add a test if you point me at where docs-site logic should be tested.
  • Documentation — inline comment explains the 90-day window and why.
  • Typings — unchanged (same return type).
  • Changelog — N/A (docs-site tracking, not the published package).

🤖 Generated with Claude Code


Generated by Claude Code

pubkey and others added 2 commits July 16, 2026 13:17
The gclid/gbraid/wbraid stored by storeAdClickId() in localStorage never
expired, so getStoredAdClickId() kept returning it indefinitely. Every later
tracking event — including organic return visits weeks or months after the ad
click — was then posted to the conversion worker attributed to that stale
click. Google Ads rejects those uploads as "this click is too old", and even
when it doesn't, crediting a much-later visit to a long-past click is wrong.

Ignore (and clear) stored click ids older than 90 days — Google Ads' maximum
click-through conversion window — so we only ever call the worker with a click
id that can still be legitimately attributed.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018HtuEgSWKF1H2RYjupj8hF
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.

1 participant