diff options
author | Minseo Lee <itoupluk427@gmail.com> | 2024-03-14 21:11:00 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-14 21:11:00 +0900 |
commit | 4813f261581e83d6d6c2c2b8063c208ecdb5de34 (patch) | |
tree | 09f498fbbbc619a2021c3bc10fada21212f28fe3 /src/lib/statsig/statsig.tsx | |
parent | 1760043f79f6e50de3bb2df97c3d6fe9c700b035 (diff) | |
parent | 1c25c76645564c4581530ec604b7862bb3b8fdda (diff) | |
download | voidsky-4813f261581e83d6d6c2c2b8063c208ecdb5de34.tar.zst |
Merge branch 'bluesky-social:main' into patch-3
Diffstat (limited to 'src/lib/statsig/statsig.tsx')
-rw-r--r-- | src/lib/statsig/statsig.tsx | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/src/lib/statsig/statsig.tsx b/src/lib/statsig/statsig.tsx index 6d9ebeb09..5745d204a 100644 --- a/src/lib/statsig/statsig.tsx +++ b/src/lib/statsig/statsig.tsx @@ -6,6 +6,9 @@ import { } from 'statsig-react-native-expo' import {useSession} from '../../state/session' import {sha256} from 'js-sha256' +import {LogEvents} from './events' + +export type {LogEvents} const statsigOptions = { environment: { @@ -17,12 +20,28 @@ const statsigOptions = { initTimeoutMs: 1, } -export function logEvent( - eventName: string, - value?: string | number | null, - metadata?: Record<string, string> | null, +type FlatJSONRecord = Record< + string, + string | number | boolean | null | undefined +> + +let getCurrentRouteName: () => string | null | undefined = () => null + +export function attachRouteToLogEvents( + getRouteName: () => string | null | undefined, +) { + getCurrentRouteName = getRouteName +} + +export function logEvent<E extends keyof LogEvents>( + eventName: E & string, + rawMetadata: LogEvents[E] & FlatJSONRecord, ) { - Statsig.logEvent(eventName, value, metadata) + const fullMetadata = { + ...rawMetadata, + } as Record<string, string> // Statsig typings are unnecessarily strict here. + fullMetadata.routeName = getCurrentRouteName() ?? '(Uninitialized)' + Statsig.logEvent(eventName, null, fullMetadata) } export function useGate(gateName: string) { |