Something went wrong. Try again.
Bluesky app fork with some witchin' additions 💫 forked from jollywhoppers.com/witchsky.app
Something went wrong. Try again.
1.3 kB · 48 lines
TSX
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import {useEffect, useRef} from 'react'
import {getCurrentState, onAppStateChange} from '#/lib/appState'import {useAnalytics} from '#/analytics'import {Features, features} from '#/analytics/features'import {IS_DEV, IS_TESTFLIGHT} from '#/env'
/** * Tracks passive analytics like app foreground/background time. */export function PassiveAnalytics() { const ax = useAnalytics() const lastActive = useRef( getCurrentState() === 'active' ? performance.now() : null, )
useEffect(() => { const sub = onAppStateChange(state => { if (state === 'active') { lastActive.current = performance.now() ax.metric('state:foreground', {}) } else if (lastActive.current !== null) { ax.metric('state:background', { secondsActive: Math.round( (performance.now() - lastActive.current) / 1e3, ), }) }
if (IS_DEV || IS_TESTFLIGHT) { const feats = Object.values(Features).reduce( (acc, feat) => { acc[feat] = features.evalFeature(feat) return acc }, {} as Record<Features, any>, ) ax.logger.info('FEATURES', { features: feats, definitions: features.getFeatures(), }) } }) return () => sub.remove() }, [ax])
return null}