Merge branch 'main' of github.com:bluesky-social/social-app into main

zio/stable
Paul Frazee 2024-03-19 20:29:13 -07:00
commit 832d5734b4
2 changed files with 13 additions and 2 deletions

View File

@ -10,7 +10,9 @@ export type LogEvents = {
logContext: 'SwitchAccount' | 'Settings' | 'Deactivated' logContext: 'SwitchAccount' | 'Settings' | 'Deactivated'
} }
'notifications:openApp': {} 'notifications:openApp': {}
'state:background': {} 'state:background': {
secondsActive: number
}
'state:foreground': {} 'state:foreground': {}
'feed:endReached': { 'feed:endReached': {
feedType: string feedType: string

View File

@ -67,15 +67,24 @@ function toStatsigUser(did: string | undefined) {
} }
let lastState: AppStateStatus = AppState.currentState let lastState: AppStateStatus = AppState.currentState
let lastActive = lastState === 'active' ? performance.now() : null
AppState.addEventListener('change', (state: AppStateStatus) => { AppState.addEventListener('change', (state: AppStateStatus) => {
if (state === lastState) { if (state === lastState) {
return return
} }
lastState = state lastState = state
if (state === 'active') { if (state === 'active') {
lastActive = performance.now()
logEvent('state:foreground', {}) logEvent('state:foreground', {})
} else { } else {
logEvent('state:background', {}) let secondsActive = 0
if (lastActive != null) {
secondsActive = Math.round((performance.now() - lastActive) / 1e3)
}
lastActive = null
logEvent('state:background', {
secondsActive,
})
} }
}) })