[Statsig] Sample router events (#4143)
parent
8cec1679a7
commit
d6625c29d1
|
@ -611,7 +611,7 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) {
|
||||||
linking={LINKING}
|
linking={LINKING}
|
||||||
theme={theme}
|
theme={theme}
|
||||||
onStateChange={() => {
|
onStateChange={() => {
|
||||||
logEvent('router:navigate', {
|
logEvent('router:navigate:sampled', {
|
||||||
from: prevLoggedRouteName.current,
|
from: prevLoggedRouteName.current,
|
||||||
})
|
})
|
||||||
prevLoggedRouteName.current = getCurrentRouteName()
|
prevLoggedRouteName.current = getCurrentRouteName()
|
||||||
|
@ -620,7 +620,7 @@ function RoutesContainer({children}: React.PropsWithChildren<{}>) {
|
||||||
attachRouteToLogEvents(getCurrentRouteName)
|
attachRouteToLogEvents(getCurrentRouteName)
|
||||||
logModuleInitTime()
|
logModuleInitTime()
|
||||||
onReady()
|
onReady()
|
||||||
logEvent('router:navigate', {})
|
logEvent('router:navigate:sampled', {})
|
||||||
}}>
|
}}>
|
||||||
{children}
|
{children}
|
||||||
</NavigationContainer>
|
</NavigationContainer>
|
||||||
|
|
|
@ -24,7 +24,7 @@ export type LogEvents = {
|
||||||
secondsActive: number
|
secondsActive: number
|
||||||
}
|
}
|
||||||
'state:foreground': {}
|
'state:foreground': {}
|
||||||
'router:navigate': {}
|
'router:navigate:sampled': {}
|
||||||
|
|
||||||
// Screen events
|
// Screen events
|
||||||
'splash:signInPressed': {}
|
'splash:signInPressed': {}
|
||||||
|
|
|
@ -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>(
|
export function logEvent<E extends keyof LogEvents>(
|
||||||
eventName: E & string,
|
eventName: E & string,
|
||||||
rawMetadata: LogEvents[E] & FlatJSONRecord,
|
rawMetadata: LogEvents[E] & FlatJSONRecord,
|
||||||
) {
|
) {
|
||||||
try {
|
try {
|
||||||
|
if (isDownsampledSession && DOWNSAMPLED_EVENTS.has(eventName)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
const fullMetadata = {
|
const fullMetadata = {
|
||||||
...rawMetadata,
|
...rawMetadata,
|
||||||
} as Record<string, string> // Statsig typings are unnecessarily strict here.
|
} as Record<string, string> // Statsig typings are unnecessarily strict here.
|
||||||
|
|
Loading…
Reference in New Issue