telemetry-first-touch-store.ts27 lines · main
| 1 | /** |
| 2 | * In-memory store for first-touch attribution data (referrer, UTMs, page URL). |
| 3 | * |
| 4 | * Captured before consent so no device storage is needed. Data is read once |
| 5 | * by PageTelemetry after consent, then cleared. Lost on hard reload — accepted |
| 6 | * trade-off (GROWTH-656). |
| 7 | */ |
| 8 | |
| 9 | import type { getSharedTelemetryData } from './telemetry-utils' |
| 10 | |
| 11 | export type SharedTelemetryData = ReturnType<typeof getSharedTelemetryData> |
| 12 | |
| 13 | let firstTouchData: SharedTelemetryData | null = null |
| 14 | |
| 15 | /** Write-once — subsequent calls are no-ops. */ |
| 16 | export function setFirstTouchData(data: SharedTelemetryData): void { |
| 17 | if (firstTouchData !== null) return |
| 18 | firstTouchData = data |
| 19 | } |
| 20 | |
| 21 | export function getFirstTouchData(): SharedTelemetryData | null { |
| 22 | return firstTouchData |
| 23 | } |
| 24 | |
| 25 | export function clearFirstTouchData(): void { |
| 26 | firstTouchData = null |
| 27 | } |