diff options
author | dan <dan.abramov@gmail.com> | 2024-05-21 04:28:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-20 20:28:12 -0700 |
commit | d6625c29d17b8c614b20378c2681b4774d7dd71f (patch) | |
tree | df5e33649dc4b6b58bdc2e3f0fc5f3651b817c81 /src | |
parent | 8cec1679a718e0cc6da67cf2604e6be8e9dab9a7 (diff) | |
download | voidsky-d6625c29d17b8c614b20378c2681b4774d7dd71f.tar.zst |
[Statsig] Sample router events (#4143)
Diffstat (limited to 'src')
-rw-r--r-- | src/Navigation.tsx | 4 | ||||
-rw-r--r-- | src/lib/statsig/events.ts | 2 | ||||
-rw-r--r-- | src/lib/statsig/statsig.tsx | 6 |
3 files changed, 9 insertions, 3 deletions
diff --git a/src/Navigation.tsx b/src/Navigation.tsx index 7abfaec08..23cf5f59d 100644 --- a/src/Navigation.tsx +++ b/src/Navigation.tsx @@ -611,7 +611,7 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) { linking={LINKING} theme={theme} onStateChange={() => { - logEvent('router:navigate', { + logEvent('router:navigate:sampled', { from: prevLoggedRouteName.current, }) prevLoggedRouteName.current = getCurrentRouteName() @@ -620,7 +620,7 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) { attachRouteToLogEvents(getCurrentRouteName) logModuleInitTime() onReady() - logEvent('router:navigate', {}) + logEvent('router:navigate:sampled', {}) }}> {children} </NavigationContainer> diff --git a/src/lib/statsig/events.ts b/src/lib/statsig/events.ts index fe4c9e65a..68de52e14 100644 --- a/src/lib/statsig/events.ts +++ b/src/lib/statsig/events.ts @@ -24,7 +24,7 @@ export type LogEvents = { secondsActive: number } 'state:foreground': {} - 'router:navigate': {} + 'router:navigate:sampled': {} // Screen events 'splash:signInPressed': {} diff --git a/src/lib/statsig/statsig.tsx b/src/lib/statsig/statsig.tsx index 005027820..b7299be8c 100644 --- a/src/lib/statsig/statsig.tsx +++ b/src/lib/statsig/statsig.tsx @@ -85,11 +85,17 @@ export function toClout(n: number | null | undefined): number | undefined { } } +const DOWNSAMPLED_EVENTS = new Set(['router:navigate:sampled']) +const isDownsampledSession = Math.random() < 0.9 // 90% likely + export function logEvent<E extends keyof LogEvents>( eventName: E & string, rawMetadata: LogEvents[E] & FlatJSONRecord, ) { try { + if (isDownsampledSession && DOWNSAMPLED_EVENTS.has(eventName)) { + return + } const fullMetadata = { ...rawMetadata, } as Record<string, string> // Statsig typings are unnecessarily strict here. |