Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs-src/src/components/trigger-event.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
Loading