diff --git a/docs-src/src/components/trigger-event.tsx b/docs-src/src/components/trigger-event.tsx index f427397e419..1be7fab82cf 100644 --- a/docs-src/src/components/trigger-event.tsx +++ b/docs-src/src/components/trigger-event.tsx @@ -36,6 +36,15 @@ const CONVERSION_WORKER_URL = 'https://rxdb-events.daniel-meyer-e90.workers.dev' */ export const AD_CLICK_STORAGE_ID = 'click_id'; +/** + * Google Ads' maximum click-through conversion window is 90 days. A stored + * click id older than that can never be imported ("this click is too old"), + * and attributing a later (often organic) visit to a months-old ad click would + * be wrong anyway. So we ignore (and clear) stale ids instead of uploading + * conversions against them forever. + */ +const AD_CLICK_MAX_AGE_MS = 90 * 24 * 60 * 60 * 1000; + function getStoredAdClickId(): { k: string; v: string; t: number; } | null { try { const raw = localStorage.getItem(AD_CLICK_STORAGE_ID); @@ -46,6 +55,10 @@ function getStoredAdClickId(): { k: string; v: string; t: number; } | null { if (!parsed || !parsed.v) { return null; } + if (typeof parsed.t !== 'number' || Date.now() - parsed.t > AD_CLICK_MAX_AGE_MS) { + localStorage.removeItem(AD_CLICK_STORAGE_ID); + return null; + } return parsed; } catch (err) { return null;