Something went wrong. Try again.
Bluesky app fork with some witchin' additions 💫 forked from jollywhoppers.com/witchsky.app
Something went wrong. Try again.
975 B · 35 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536import {useCallback, useRef} from 'react'
import {type Metrics, useAnalytics} from '#/analytics'import {type app} from '#/lexicons'
/** * Hook that returns a callback to track post:view events. * Handles deduplication so the same post URI is only tracked once per mount. * * @param logContext - The context where the post is being viewed * @returns A callback that accepts a post and logs the view event */export function usePostViewTracking( logContext: Metrics['post:view']['logContext'],) { const ax = useAnalytics() const seenUrisRef = useRef(new Set<string>())
const trackPostView = useCallback( (post: app.bsky.feed.defs.PostView) => { if (seenUrisRef.current.has(post.uri)) return seenUrisRef.current.add(post.uri)
ax.metric('post:view', { uri: post.uri, authorDid: post.author.did, isReply: !!post.record.reply, logContext, }) }, [ax, logContext], )
return trackPostView}