[Statsig] Track feed refresh (#3283)

zio/stable
dan 2024-03-20 00:56:31 +00:00 committed by GitHub
parent 54f424d047
commit b6c9d34e45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 2 deletions

View File

@ -9,6 +9,10 @@ export type LogEvents = {
feedType: string
itemCount: number
}
'feed:refresh': {
feedType: string
reason: 'pull-to-refresh' | 'soft-reset' | 'load-latest'
}
'post:create': {
imageCount: number
isReply: boolean

View File

@ -22,6 +22,7 @@ import {listenSoftReset} from '#/state/events'
import {truncateAndInvalidate} from '#/state/queries/util'
import {TabState, getTabState, getRootNavigation} from '#/lib/routes/helpers'
import {isNative} from '#/platform/detection'
import {logEvent} from '#/lib/statsig/statsig'
const POLL_FREQ = 60e3 // 60sec
@ -68,6 +69,10 @@ export function FeedPage({
scrollToTop()
truncateAndInvalidate(queryClient, FEED_RQKEY(feed))
setHasNew(false)
logEvent('feed:refresh', {
feedType: feed.split('|')[0],
reason: 'soft-reset',
})
}
}, [navigation, isPageFocused, scrollToTop, queryClient, feed, setHasNew])
@ -89,6 +94,10 @@ export function FeedPage({
scrollToTop()
truncateAndInvalidate(queryClient, FEED_RQKEY(feed))
setHasNew(false)
logEvent('feed:refresh', {
feedType: feed.split('|')[0],
reason: 'load-latest',
})
}, [scrollToTop, feed, queryClient, setHasNew])
return (

View File

@ -90,6 +90,7 @@ let Feed = ({
const [isPTRing, setIsPTRing] = React.useState(false)
const checkForNewRef = React.useRef<(() => void) | null>(null)
const lastFetchRef = React.useRef<number>(Date.now())
const feedType = feed.split('|')[0]
const opts = React.useMemo(
() => ({enabled, ignoreFilterFor}),
@ -214,6 +215,10 @@ let Feed = ({
const onRefresh = React.useCallback(async () => {
track('Feed:onRefresh')
logEvent('feed:refresh', {
feedType: feedType,
reason: 'pull-to-refresh',
})
setIsPTRing(true)
try {
await refetch()
@ -222,9 +227,8 @@ let Feed = ({
logger.error('Failed to refresh posts feed', {message: err})
}
setIsPTRing(false)
}, [refetch, track, setIsPTRing, onHasNew])
}, [refetch, track, setIsPTRing, onHasNew, feedType])
const feedType = feed.split('|')[0]
const onEndReached = React.useCallback(async () => {
if (isFetching || !hasNextPage || isError) return