Bluesky app fork with some witchin' additions 馃挮 witchsky.app
bluesky fork client
at main 32 lines 850 B view raw
1import {useEffect, useRef} from 'react' 2 3import {getCurrentState, onAppStateChange} from '#/lib/appState' 4import {useAnalytics} from '#/analytics' 5 6/** 7 * Tracks passive analytics like app foreground/background time. 8 */ 9export function PassiveAnalytics() { 10 const ax = useAnalytics() 11 const lastActive = useRef( 12 getCurrentState() === 'active' ? performance.now() : null, 13 ) 14 15 useEffect(() => { 16 const sub = onAppStateChange(state => { 17 if (state === 'active') { 18 lastActive.current = performance.now() 19 ax.metric('state:foreground', {}) 20 } else if (lastActive.current !== null) { 21 ax.metric('state:background', { 22 secondsActive: Math.round( 23 (performance.now() - lastActive.current) / 1e3, 24 ), 25 }) 26 } 27 }) 28 return () => sub.remove() 29 }, [ax]) 30 31 return null 32}