Add more client events to profile followers/following pages (#9466)

* Add more client events to profile followers/following pages

* Remove unneeded logContext attribute
This commit is contained in:
Alex Benzer
2025-12-05 08:27:35 -08:00
committed by GitHub
parent d3878bf0ac
commit 6686ebc232
3 changed files with 91 additions and 1 deletions
+18
View File
@@ -301,6 +301,24 @@ export type MetricEvents = {
| 'ExploreSuggestedAccounts'
| 'OnboardingSuggestedAccounts'
}
'profile:followers:view': {
contextProfileDid: string
isOwnProfile: boolean
}
'profile:followers:paginate': {
contextProfileDid: string
itemCount: number
page: number
}
'profile:following:view': {
contextProfileDid: string
isOwnProfile: boolean
}
'profile:following:paginate': {
contextProfileDid: string
itemCount: number
page: number
}
'profileCard:seen': {
contextProfileDid?: string
profileDid: string
+36
View File
@@ -71,6 +71,32 @@ export function ProfileFollowers({name}: {name: string}) {
return []
}, [data])
// Track pagination events - fire for page 3+ (pages 1-2 may auto-load)
const paginationTrackingRef = React.useRef<{
did: string | undefined
page: number
}>({did: undefined, page: 0})
React.useEffect(() => {
const currentPageCount = data?.pages?.length || 0
// Reset tracking when profile changes
if (paginationTrackingRef.current.did !== resolvedDid) {
paginationTrackingRef.current = {did: resolvedDid, page: currentPageCount}
return
}
if (
resolvedDid &&
currentPageCount >= 3 &&
currentPageCount > paginationTrackingRef.current.page
) {
logger.metric('profile:followers:paginate', {
contextProfileDid: resolvedDid,
itemCount: followers.length,
page: currentPageCount,
})
}
paginationTrackingRef.current.page = currentPageCount
}, [data?.pages?.length, resolvedDid, followers.length])
const onRefresh = React.useCallback(async () => {
setIsPTRing(true)
try {
@@ -96,6 +122,16 @@ export function ProfileFollowers({name}: {name: string}) {
[resolvedDid],
)
// track pageview
React.useEffect(() => {
if (resolvedDid) {
logger.metric('profile:followers:view', {
contextProfileDid: resolvedDid,
isOwnProfile: isMe,
})
}
}, [resolvedDid, isMe])
// track seen items
const seenItemsRef = React.useRef<Set<string>>(new Set())
React.useEffect(() => {
+37 -1
View File
@@ -82,6 +82,32 @@ export function ProfileFollows({name}: {name: string}) {
return []
}, [data])
// Track pagination events - fire for page 3+ (pages 1-2 may auto-load)
const paginationTrackingRef = React.useRef<{
did: string | undefined
page: number
}>({did: undefined, page: 0})
React.useEffect(() => {
const currentPageCount = data?.pages?.length || 0
// Reset tracking when profile changes
if (paginationTrackingRef.current.did !== resolvedDid) {
paginationTrackingRef.current = {did: resolvedDid, page: currentPageCount}
return
}
if (
resolvedDid &&
currentPageCount >= 3 &&
currentPageCount > paginationTrackingRef.current.page
) {
logger.metric('profile:following:paginate', {
contextProfileDid: resolvedDid,
itemCount: follows.length,
page: currentPageCount,
})
}
paginationTrackingRef.current.page = currentPageCount
}, [data?.pages?.length, resolvedDid, follows.length])
const onRefresh = React.useCallback(async () => {
setIsPTRing(true)
try {
@@ -99,7 +125,7 @@ export function ProfileFollows({name}: {name: string}) {
} catch (err) {
logger.error('Failed to load more follows', {error: err})
}
}, [error, fetchNextPage, hasNextPage, isFetchingNextPage])
}, [isFetchingNextPage, hasNextPage, error, fetchNextPage])
const renderItemWithContext = React.useCallback(
({item, index}: {item: ActorDefs.ProfileView; index: number}) =>
@@ -107,6 +133,16 @@ export function ProfileFollows({name}: {name: string}) {
[resolvedDid],
)
// track pageview
React.useEffect(() => {
if (resolvedDid) {
logger.metric('profile:following:view', {
contextProfileDid: resolvedDid,
isOwnProfile: isMe,
})
}
}, [resolvedDid, isMe])
// track seen items
const seenItemsRef = React.useRef<Set<string>>(new Set())
React.useEffect(() => {