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
9import type { getSharedTelemetryData } from './telemetry-utils'
10
11export type SharedTelemetryData = ReturnType<typeof getSharedTelemetryData>
12
13let firstTouchData: SharedTelemetryData | null = null
14
15/** Write-once — subsequent calls are no-ops. */
16export function setFirstTouchData(data: SharedTelemetryData): void {
17 if (firstTouchData !== null) return
18 firstTouchData = data
19}
20
21export function getFirstTouchData(): SharedTelemetryData | null {
22 return firstTouchData
23}
24
25export function clearFirstTouchData(): void {
26 firstTouchData = null
27}