diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-03-20 15:37:14 +0000 |
---|---|---|
committer | Samuel Newman <mozzius@protonmail.com> | 2024-03-20 15:37:14 +0000 |
commit | d24ffba01d7aa5a505b4e3d319dfecffc3d039ca (patch) | |
tree | 4e860ca6a6dd038f41bba1839d180177b70c877b /src/lib/statsig | |
parent | 2fa26ceedc1c7f6f3c4a1bdeab621b34c24bcb17 (diff) | |
parent | 023e12bb4ec1dade373c810a13d8bba6d96a22be (diff) | |
download | voidsky-d24ffba01d7aa5a505b4e3d319dfecffc3d039ca.tar.zst |
Merge remote-tracking branch 'origin/main' into samuel/alf-login
Diffstat (limited to 'src/lib/statsig')
-rw-r--r-- | src/lib/statsig/events.ts | 16 | ||||
-rw-r--r-- | src/lib/statsig/statsig.tsx | 29 |
2 files changed, 44 insertions, 1 deletions
diff --git a/src/lib/statsig/events.ts b/src/lib/statsig/events.ts index fa7e597fb..b83095976 100644 --- a/src/lib/statsig/events.ts +++ b/src/lib/statsig/events.ts @@ -2,10 +2,26 @@ export type LogEvents = { init: { initMs: number } + 'account:loggedIn': { + logContext: 'LoginForm' | 'SwitchAccount' | 'ChooseAccountForm' | 'Settings' + withPassword: boolean + } + 'account:loggedOut': { + logContext: 'SwitchAccount' | 'Settings' | 'Deactivated' + } + 'notifications:openApp': {} + 'state:background': { + secondsActive: number + } + 'state:foreground': {} 'feed:endReached': { feedType: string itemCount: number } + 'feed:refresh': { + feedType: string + reason: 'pull-to-refresh' | 'soft-reset' | 'load-latest' + } 'post:create': { imageCount: number isReply: boolean diff --git a/src/lib/statsig/statsig.tsx b/src/lib/statsig/statsig.tsx index 5745d204a..9fa6cce2d 100644 --- a/src/lib/statsig/statsig.tsx +++ b/src/lib/statsig/statsig.tsx @@ -1,9 +1,11 @@ import React from 'react' +import {Platform} from 'react-native' import { Statsig, StatsigProvider, useGate as useStatsigGate, } from 'statsig-react-native-expo' +import {AppState, AppStateStatus} from 'react-native' import {useSession} from '../../state/session' import {sha256} from 'js-sha256' import {LogEvents} from './events' @@ -58,9 +60,34 @@ function toStatsigUser(did: string | undefined) { if (did) { userID = sha256(did) } - return {userID} + return { + userID, + platform: Platform.OS, + } } +let lastState: AppStateStatus = AppState.currentState +let lastActive = lastState === 'active' ? performance.now() : null +AppState.addEventListener('change', (state: AppStateStatus) => { + if (state === lastState) { + return + } + lastState = state + if (state === 'active') { + lastActive = performance.now() + logEvent('state:foreground', {}) + } else { + let secondsActive = 0 + if (lastActive != null) { + secondsActive = Math.round((performance.now() - lastActive) / 1e3) + } + lastActive = null + logEvent('state:background', { + secondsActive, + }) + } +}) + export function Provider({children}: {children: React.ReactNode}) { const {currentAccount} = useSession() const currentStatsigUser = React.useMemo( |