Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Send route name with Statsig events (#3194)

* Add types to Statsig events

* Send route name with events

authored by

dan and committed by
GitHub
f1d55f49 653240bc

+36 -7
+9 -2
src/Navigation.tsx
··· 78 78 import {msg} from '@lingui/macro' 79 79 import {i18n, MessageDescriptor} from '@lingui/core' 80 80 import HashtagScreen from '#/screens/Hashtag' 81 - import {logEvent} from './lib/statsig/statsig' 81 + import {logEvent, attachRouteToLogEvents} from './lib/statsig/statsig' 82 82 83 83 const navigationRef = createNavigationContainerRef<AllNavigatorParams>() 84 84 ··· 543 543 linking={LINKING} 544 544 theme={theme} 545 545 onReady={() => { 546 + attachRouteToLogEvents(getCurrentRouteName) 546 547 logModuleInitTime() 547 548 onReady() 548 549 }}> 549 550 {children} 550 551 </NavigationContainer> 551 552 ) 553 + } 554 + 555 + function getCurrentRouteName() { 556 + return navigationRef.getCurrentRoute()?.name 552 557 } 553 558 554 559 /** ··· 656 661 performance.now() - global.__BUNDLE_START_TIME__, 657 662 ) 658 663 console.log(`Time to first paint: ${initMs} ms`) 659 - logEvent('init', initMs) 664 + logEvent('init', { 665 + initMs, 666 + }) 660 667 661 668 if (__DEV__) { 662 669 // This log is noisy, so keep false committed
+5
src/lib/statsig/events.ts
··· 1 + export type Events = { 2 + init: { 3 + initMs: number 4 + } 5 + }
+22 -5
src/lib/statsig/statsig.tsx
··· 6 6 } from 'statsig-react-native-expo' 7 7 import {useSession} from '../../state/session' 8 8 import {sha256} from 'js-sha256' 9 + import {Events} from './events' 9 10 10 11 const statsigOptions = { 11 12 environment: { ··· 17 18 initTimeoutMs: 1, 18 19 } 19 20 20 - export function logEvent( 21 - eventName: string, 22 - value?: string | number | null, 23 - metadata?: Record<string, string> | null, 21 + type FlatJSONRecord = Record< 22 + string, 23 + string | number | boolean | null | undefined 24 + > 25 + 26 + let getCurrentRouteName: () => string | null | undefined = () => null 27 + 28 + export function attachRouteToLogEvents( 29 + getRouteName: () => string | null | undefined, 30 + ) { 31 + getCurrentRouteName = getRouteName 32 + } 33 + 34 + export function logEvent<E extends keyof Events>( 35 + eventName: E & string, 36 + rawMetadata?: Events[E] & FlatJSONRecord, 24 37 ) { 25 - Statsig.logEvent(eventName, value, metadata) 38 + const fullMetadata = { 39 + ...rawMetadata, 40 + } as Record<string, string> // Statsig typings are unnecessarily strict here. 41 + fullMetadata.routeName = getCurrentRouteName() ?? '(Uninitialized)' 42 + Statsig.logEvent(eventName, null, fullMetadata) 26 43 } 27 44 28 45 export function useGate(gateName: string) {