···11+import {useCallback, useRef} from 'react'
22+import {type AppBskyFeedDefs} from '@atproto/api'
33+44+import {logger} from '#/logger'
55+import {type MetricEvents} from '#/logger/metrics'
66+77+/**
88+ * Hook that returns a callback to track post:view events.
99+ * Handles deduplication so the same post URI is only tracked once per mount.
1010+ *
1111+ * @param logContext - The context where the post is being viewed
1212+ * @returns A callback that accepts a post and logs the view event
1313+ */
1414+export function usePostViewTracking(
1515+ logContext: MetricEvents['post:view']['logContext'],
1616+) {
1717+ const seenUrisRef = useRef(new Set<string>())
1818+1919+ const trackPostView = useCallback(
2020+ (post: AppBskyFeedDefs.PostView) => {
2121+ if (seenUrisRef.current.has(post.uri)) return
2222+ seenUrisRef.current.add(post.uri)
2323+2424+ logger.metric(
2525+ 'post:view',
2626+ {
2727+ uri: post.uri,
2828+ authorDid: post.author.did,
2929+ logContext,
3030+ },
3131+ {statsig: false},
3232+ )
3333+ },
3434+ [logContext],
3535+ )
3636+3737+ return trackPostView
3838+}