[Statsig] Include OS and track app state changes (#3273)
* Include platform in identify * Track back/foregroundingzio/stable
parent
e9222a9d97
commit
5bec587717
|
@ -2,6 +2,8 @@ export type LogEvents = {
|
||||||
init: {
|
init: {
|
||||||
initMs: number
|
initMs: number
|
||||||
}
|
}
|
||||||
|
'state:background': {}
|
||||||
|
'state:foreground': {}
|
||||||
'feed:endReached': {
|
'feed:endReached': {
|
||||||
feedType: string
|
feedType: string
|
||||||
itemCount: number
|
itemCount: number
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import {Platform} from 'react-native'
|
||||||
import {
|
import {
|
||||||
Statsig,
|
Statsig,
|
||||||
StatsigProvider,
|
StatsigProvider,
|
||||||
useGate as useStatsigGate,
|
useGate as useStatsigGate,
|
||||||
} from 'statsig-react-native-expo'
|
} from 'statsig-react-native-expo'
|
||||||
|
import {AppState, AppStateStatus} from 'react-native'
|
||||||
import {useSession} from '../../state/session'
|
import {useSession} from '../../state/session'
|
||||||
import {sha256} from 'js-sha256'
|
import {sha256} from 'js-sha256'
|
||||||
import {LogEvents} from './events'
|
import {LogEvents} from './events'
|
||||||
|
@ -58,9 +60,25 @@ function toStatsigUser(did: string | undefined) {
|
||||||
if (did) {
|
if (did) {
|
||||||
userID = sha256(did)
|
userID = sha256(did)
|
||||||
}
|
}
|
||||||
return {userID}
|
return {
|
||||||
|
userID,
|
||||||
|
platform: Platform.OS,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let lastState: AppStateStatus = AppState.currentState
|
||||||
|
AppState.addEventListener('change', (state: AppStateStatus) => {
|
||||||
|
if (state === lastState) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
lastState = state
|
||||||
|
if (state === 'active') {
|
||||||
|
logEvent('state:foreground', {})
|
||||||
|
} else {
|
||||||
|
logEvent('state:background', {})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
export function Provider({children}: {children: React.ReactNode}) {
|
export function Provider({children}: {children: React.ReactNode}) {
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const currentStatsigUser = React.useMemo(
|
const currentStatsigUser = React.useMemo(
|
||||||
|
|
Loading…
Reference in New Issue