Skip to content

Commit 6686ebc

Browse files
authored
Add more client events to profile followers/following pages (#9466)
* Add more client events to profile followers/following pages * Remove unneeded logContext attribute
1 parent d3878bf commit 6686ebc

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

src/logger/metrics.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,24 @@ export type MetricEvents = {
301301
| 'ExploreSuggestedAccounts'
302302
| 'OnboardingSuggestedAccounts'
303303
}
304+
'profile:followers:view': {
305+
contextProfileDid: string
306+
isOwnProfile: boolean
307+
}
308+
'profile:followers:paginate': {
309+
contextProfileDid: string
310+
itemCount: number
311+
page: number
312+
}
313+
'profile:following:view': {
314+
contextProfileDid: string
315+
isOwnProfile: boolean
316+
}
317+
'profile:following:paginate': {
318+
contextProfileDid: string
319+
itemCount: number
320+
page: number
321+
}
304322
'profileCard:seen': {
305323
contextProfileDid?: string
306324
profileDid: string

src/view/com/profile/ProfileFollowers.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,32 @@ export function ProfileFollowers({name}: {name: string}) {
7171
return []
7272
}, [data])
7373

74+
// Track pagination events - fire for page 3+ (pages 1-2 may auto-load)
75+
const paginationTrackingRef = React.useRef<{
76+
did: string | undefined
77+
page: number
78+
}>({did: undefined, page: 0})
79+
React.useEffect(() => {
80+
const currentPageCount = data?.pages?.length || 0
81+
// Reset tracking when profile changes
82+
if (paginationTrackingRef.current.did !== resolvedDid) {
83+
paginationTrackingRef.current = {did: resolvedDid, page: currentPageCount}
84+
return
85+
}
86+
if (
87+
resolvedDid &&
88+
currentPageCount >= 3 &&
89+
currentPageCount > paginationTrackingRef.current.page
90+
) {
91+
logger.metric('profile:followers:paginate', {
92+
contextProfileDid: resolvedDid,
93+
itemCount: followers.length,
94+
page: currentPageCount,
95+
})
96+
}
97+
paginationTrackingRef.current.page = currentPageCount
98+
}, [data?.pages?.length, resolvedDid, followers.length])
99+
74100
const onRefresh = React.useCallback(async () => {
75101
setIsPTRing(true)
76102
try {
@@ -96,6 +122,16 @@ export function ProfileFollowers({name}: {name: string}) {
96122
[resolvedDid],
97123
)
98124

125+
// track pageview
126+
React.useEffect(() => {
127+
if (resolvedDid) {
128+
logger.metric('profile:followers:view', {
129+
contextProfileDid: resolvedDid,
130+
isOwnProfile: isMe,
131+
})
132+
}
133+
}, [resolvedDid, isMe])
134+
99135
// track seen items
100136
const seenItemsRef = React.useRef<Set<string>>(new Set())
101137
React.useEffect(() => {

src/view/com/profile/ProfileFollows.tsx

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,32 @@ export function ProfileFollows({name}: {name: string}) {
8282
return []
8383
}, [data])
8484

85+
// Track pagination events - fire for page 3+ (pages 1-2 may auto-load)
86+
const paginationTrackingRef = React.useRef<{
87+
did: string | undefined
88+
page: number
89+
}>({did: undefined, page: 0})
90+
React.useEffect(() => {
91+
const currentPageCount = data?.pages?.length || 0
92+
// Reset tracking when profile changes
93+
if (paginationTrackingRef.current.did !== resolvedDid) {
94+
paginationTrackingRef.current = {did: resolvedDid, page: currentPageCount}
95+
return
96+
}
97+
if (
98+
resolvedDid &&
99+
currentPageCount >= 3 &&
100+
currentPageCount > paginationTrackingRef.current.page
101+
) {
102+
logger.metric('profile:following:paginate', {
103+
contextProfileDid: resolvedDid,
104+
itemCount: follows.length,
105+
page: currentPageCount,
106+
})
107+
}
108+
paginationTrackingRef.current.page = currentPageCount
109+
}, [data?.pages?.length, resolvedDid, follows.length])
110+
85111
const onRefresh = React.useCallback(async () => {
86112
setIsPTRing(true)
87113
try {
@@ -99,14 +125,24 @@ export function ProfileFollows({name}: {name: string}) {
99125
} catch (err) {
100126
logger.error('Failed to load more follows', {error: err})
101127
}
102-
}, [error, fetchNextPage, hasNextPage, isFetchingNextPage])
128+
}, [isFetchingNextPage, hasNextPage, error, fetchNextPage])
103129

104130
const renderItemWithContext = React.useCallback(
105131
({item, index}: {item: ActorDefs.ProfileView; index: number}) =>
106132
renderItem({item, index, contextProfileDid: resolvedDid}),
107133
[resolvedDid],
108134
)
109135

136+
// track pageview
137+
React.useEffect(() => {
138+
if (resolvedDid) {
139+
logger.metric('profile:following:view', {
140+
contextProfileDid: resolvedDid,
141+
isOwnProfile: isMe,
142+
})
143+
}
144+
}, [resolvedDid, isMe])
145+
110146
// track seen items
111147
const seenItemsRef = React.useRef<Set<string>>(new Set())
112148
React.useEffect(() => {

0 commit comments

Comments
 (0)