mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
## Changes Introduces two new files in `packages/common`: - **`telemetry-first-touch-store.ts`** — a module-scoped singleton that holds first-touch attribution data (referrer, UTM params, page URL) in memory. Writes once on first load, cleared after the initial pageview event fires or on opt-out. No device storage involved. - **`useFirstTouchStore.tsx`** — a React hook that captures attribution data on initial page load and writes it into the store, gated on the `enabled` flag so it only runs where consent has been handled. Trade-off: data is lost on a hard reload before consent is granted — accepted edge case per GROWTH-656. Follows the same module-scope pattern already used by `posthogClient` and `consentState`. ## Testing - Verify first-touch data is captured on initial load and readable by `PageTelemetry` after consent - Verify no cookie is set before consent - Verify data is cleared after initial pageview fires GROWTH-656
28 lines
825 B
TypeScript
28 lines
825 B
TypeScript
/**
|
|
* In-memory store for first-touch attribution data (referrer, UTMs, page URL).
|
|
*
|
|
* Captured before consent so no device storage is needed. Data is read once
|
|
* by PageTelemetry after consent, then cleared. Lost on hard reload — accepted
|
|
* trade-off (GROWTH-656).
|
|
*/
|
|
|
|
import type { getSharedTelemetryData } from './telemetry-utils'
|
|
|
|
export type SharedTelemetryData = ReturnType<typeof getSharedTelemetryData>
|
|
|
|
let firstTouchData: SharedTelemetryData | null = null
|
|
|
|
/** Write-once — subsequent calls are no-ops. */
|
|
export function setFirstTouchData(data: SharedTelemetryData): void {
|
|
if (firstTouchData !== null) return
|
|
firstTouchData = data
|
|
}
|
|
|
|
export function getFirstTouchData(): SharedTelemetryData | null {
|
|
return firstTouchData
|
|
}
|
|
|
|
export function clearFirstTouchData(): void {
|
|
firstTouchData = null
|
|
}
|