docs: expire stale ad click ids before sending conversions to the worker#8799
Open
pubkey wants to merge 2 commits into
Open
docs: expire stale ad click ids before sending conversions to the worker#8799pubkey wants to merge 2 commits into
pubkey wants to merge 2 commits into
Conversation
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
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018HtuEgSWKF1H2RYjupj8hF
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.
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 thegclid/gbraid/wbraidfrom the landing URL intolocalStorageunderclick_id, andgetStoredAdClickId()(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-adsattributed to the old click. Two concrete problems: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()returnsnulland 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
docs-src(Docusaurus site tracking code), which has no unit-test harness in this repo (thetest/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.🤖 Generated with Claude Code
Generated by Claude Code