Fire the post:view client event in more places, anywhere a post can be seen (#9467)

* Fire the post:view client event in more places

* Fix bad import

---------

Co-authored-by: Eric Bailey <git@esb.lol>
This commit is contained in:
Alex Benzer
2025-12-05 10:32:19 -08:00
committed by GitHub
parent db81cefb86
commit 9a0cb09d3a
10 changed files with 120 additions and 3 deletions
+10
View File
@@ -5,6 +5,7 @@ import {Trans} from '@lingui/macro'
import {useInitialNumToRender} from '#/lib/hooks/useInitialNumToRender'
import {useOpenComposer} from '#/lib/hooks/useOpenComposer'
import {usePostViewTracking} from '#/lib/hooks/usePostViewTracking'
import {logger} from '#/logger'
import {useFeedFeedback} from '#/state/feed-feedback'
import {type ThreadViewOption} from '#/state/queries/preferences/useThreadPreferences'
@@ -97,6 +98,9 @@ export function PostThread({uri}: {uri: string}) {
}
}, [anchor, feedFeedback.feedDescriptor])
// Track post:view events for parent posts and replies (non-anchor posts)
const trackThreadItemView = usePostViewTracking('PostThreadItem')
const {openComposer} = useOpenComposer()
const optimisticOnPostReply = useCallback(
(payload: OnPostSuccessData) => {
@@ -557,6 +561,12 @@ export function PostThread({uri}: {uri: string}) {
onEndReached={onEndReached}
onEndReachedThreshold={4}
onStartReachedThreshold={1}
onItemSeen={item => {
// Track post:view for parent posts and replies (non-anchor posts)
if (item.type === 'threadPost' && item.depth !== 0) {
trackThreadItemView(item.value.post)
}
}}
/**
* NATIVE ONLY
* {@link https://reactnative.dev/docs/scrollview#maintainvisiblecontentposition}