Fix the 'seen' metric in explore (#8134)

This commit is contained in:
Paul Frazee
2025-04-04 17:28:02 -07:00
committed by GitHub
parent 502d660eb4
commit a301e31f76
2 changed files with 27 additions and 32 deletions
+22 -32
View File
@@ -1,5 +1,5 @@
import {useCallback, useMemo, useRef, useState} from 'react' import {useCallback, useMemo, useRef, useState} from 'react'
import {View, type ViewabilityConfig, type ViewToken} from 'react-native' import {View, type ViewabilityConfig} from 'react-native'
import { import {
type AppBskyActorDefs, type AppBskyActorDefs,
type AppBskyFeedDefs, type AppBskyFeedDefs,
@@ -837,36 +837,26 @@ export function Explore({
// track headers and report module viewability // track headers and report module viewability
const alreadyReportedRef = useRef<Map<string, string>>(new Map()) const alreadyReportedRef = useRef<Map<string, string>>(new Map())
const onViewableItemsChanged = useCallback( const onItemSeen = useCallback((item: ExploreScreenItems) => {
({ let module: MetricEvents['explore:module:seen']['module']
viewableItems, if (item.type === 'trendingTopics' || item.type === 'trendingVideos') {
}: { module = item.type
viewableItems: ViewToken<ExploreScreenItems>[] } else if (item.type === 'profile') {
changed: ViewToken<ExploreScreenItems>[] module = 'suggestedAccounts'
}) => { } else if (item.type === 'feed') {
for (const {item, index} of viewableItems.filter(vi => vi.isViewable)) { module = 'suggestedFeeds'
let module: MetricEvents['explore:module:seen']['module'] } else if (item.type === 'starterPack') {
if (item.type === 'trendingTopics' || item.type === 'trendingVideos') { module = 'suggestedStarterPacks'
module = item.type } else if (item.type === 'preview:sliceItem') {
} else if (item.type === 'profile') { module = `feed:feedgen|${item.feed.uri}`
module = 'suggestedAccounts' } else {
} else if (item.type === 'feed') { return
module = 'suggestedFeeds' }
} else if (item.type === 'starterPack') { if (!alreadyReportedRef.current.has(module)) {
module = 'suggestedStarterPacks' alreadyReportedRef.current.set(module, module)
} else if (item.type === 'preview:header') { logger.metric('explore:module:seen', {module}) //, index: index ?? -1})
module = `feed:feedgen|${item.feed.uri}` }
} else { }, [])
continue
}
if (!alreadyReportedRef.current.has(module)) {
alreadyReportedRef.current.set(module, module)
logger.metric('explore:module:seen', {module, index: index ?? -1})
}
}
},
[],
)
return ( return (
<List <List
@@ -879,7 +869,7 @@ export function Explore({
keyboardDismissMode="on-drag" keyboardDismissMode="on-drag"
stickyHeaderIndices={native(stickyHeaderIndices)} stickyHeaderIndices={native(stickyHeaderIndices)}
viewabilityConfig={viewabilityConfig} viewabilityConfig={viewabilityConfig}
onViewableItemsChanged={onViewableItemsChanged} onItemSeen={onItemSeen}
onEndReached={onLoadMoreFeedPreviews} onEndReached={onLoadMoreFeedPreviews}
onEndReachedThreshold={3} onEndReachedThreshold={3}
initialNumToRender={initialNumToRender} initialNumToRender={initialNumToRender}
@@ -73,6 +73,7 @@ export type FeedPreviewItem =
key: string key: string
slice: FeedPostSlice slice: FeedPostSlice
indexInSlice: number indexInSlice: number
feed: AppBskyFeedDefs.GeneratorView
showReplyTo: boolean showReplyTo: boolean
hideTopBorder: boolean hideTopBorder: boolean
} }
@@ -202,6 +203,7 @@ export function useFeedPreviews(
key: slice.items[0]._reactKey, key: slice.items[0]._reactKey,
slice: slice, slice: slice,
indexInSlice: 0, indexInSlice: 0,
feed: page.feed,
showReplyTo: false, showReplyTo: false,
hideTopBorder: rowIndex === 0, hideTopBorder: rowIndex === 0,
}) })
@@ -215,6 +217,7 @@ export function useFeedPreviews(
key: slice.items[beforeLast]._reactKey, key: slice.items[beforeLast]._reactKey,
slice: slice, slice: slice,
indexInSlice: beforeLast, indexInSlice: beforeLast,
feed: page.feed,
showReplyTo: showReplyTo:
slice.items[beforeLast].parentAuthor?.did !== slice.items[beforeLast].parentAuthor?.did !==
slice.items[beforeLast].post.author.did, slice.items[beforeLast].post.author.did,
@@ -225,6 +228,7 @@ export function useFeedPreviews(
key: slice.items[last]._reactKey, key: slice.items[last]._reactKey,
slice: slice, slice: slice,
indexInSlice: last, indexInSlice: last,
feed: page.feed,
showReplyTo: false, showReplyTo: false,
hideTopBorder: false, hideTopBorder: false,
}) })
@@ -235,6 +239,7 @@ export function useFeedPreviews(
key: slice.items[i]._reactKey, key: slice.items[i]._reactKey,
slice: slice, slice: slice,
indexInSlice: i, indexInSlice: i,
feed: page.feed,
showReplyTo: i === 0, showReplyTo: i === 0,
hideTopBorder: i === 0 && rowIndex === 0, hideTopBorder: i === 0 && rowIndex === 0,
}) })