telemetry-first-touch-store.ts 825 B

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