@@ -12,7 +12,6 @@ import throttle from 'lodash.throttle'
12
12
13
13
import { PROD_FEEDS , STAGING_FEEDS } from '#/lib/constants'
14
14
import { isNetworkError } from '#/lib/hooks/useCleanError'
15
- import { logEvent } from '#/lib/statsig/statsig'
16
15
import { Logger } from '#/logger'
17
16
import {
18
17
type FeedSourceFeedInfo ,
@@ -90,11 +89,19 @@ export function useFeedFeedback(
90
89
const aggregatedStats = useRef < AggregatedStats | null > ( null )
91
90
const throttledFlushAggregatedStats = useMemo (
92
91
( ) =>
93
- throttle ( ( ) => flushToStatsig ( aggregatedStats . current ) , 45e3 , {
94
- leading : true , // The outer call is already throttled somewhat.
95
- trailing : true ,
96
- } ) ,
97
- [ ] ,
92
+ throttle (
93
+ ( ) =>
94
+ flushToStatsig (
95
+ aggregatedStats . current ,
96
+ feed ?. feedDescriptor ?? 'unknown' ,
97
+ ) ,
98
+ 45e3 ,
99
+ {
100
+ leading : true , // The outer call is already throttled somewhat.
101
+ trailing : true ,
102
+ } ,
103
+ ) ,
104
+ [ feed ?. feedDescriptor ] ,
98
105
)
99
106
100
107
const sendToFeedNoDelay = useCallback ( ( ) => {
@@ -135,6 +142,7 @@ export function useFeedFeedback(
135
142
sendOrAggregateInteractionsForStats (
136
143
aggregatedStats . current ,
137
144
interactionsToSend ,
145
+ feed ?. feedDescriptor ?? 'unknown' ,
138
146
)
139
147
throttledFlushAggregatedStats ( )
140
148
logger . debug ( 'flushed' )
@@ -271,19 +279,22 @@ function createAggregatedStats(): AggregatedStats {
271
279
function sendOrAggregateInteractionsForStats (
272
280
stats : AggregatedStats ,
273
281
interactions : AppBskyFeedDefs . Interaction [ ] ,
282
+ feed : string ,
274
283
) {
275
284
for ( let interaction of interactions ) {
276
285
switch ( interaction . event ) {
277
286
// Pressing "Show more" / "Show less" is relatively uncommon so we won't aggregate them.
278
287
// This lets us send the feed context together with them.
279
288
case 'app.bsky.feed.defs#requestLess' : {
280
- logEvent ( 'discover:showLess' , {
289
+ logger . metric ( 'feed:showLess' , {
290
+ feed,
281
291
feedContext : interaction . feedContext ?? '' ,
282
292
} )
283
293
break
284
294
}
285
295
case 'app.bsky.feed.defs#requestMore' : {
286
- logEvent ( 'discover:showMore' , {
296
+ logger . metric ( 'feed:showMore' , {
297
+ feed,
287
298
feedContext : interaction . feedContext ?? '' ,
288
299
} )
289
300
break
@@ -313,28 +324,31 @@ function sendOrAggregateInteractionsForStats(
313
324
}
314
325
}
315
326
316
- function flushToStatsig ( stats : AggregatedStats | null ) {
327
+ function flushToStatsig ( stats : AggregatedStats | null , feedDescriptor : string ) {
317
328
if ( stats === null ) {
318
329
return
319
330
}
320
331
321
332
if ( stats . clickthroughCount > 0 ) {
322
- logEvent ( 'discover :clickthrough', {
333
+ logger . metric ( 'feed :clickthrough', {
323
334
count : stats . clickthroughCount ,
335
+ feed : feedDescriptor ,
324
336
} )
325
337
stats . clickthroughCount = 0
326
338
}
327
339
328
340
if ( stats . engagedCount > 0 ) {
329
- logEvent ( 'discover :engaged', {
341
+ logger . metric ( 'feed :engaged', {
330
342
count : stats . engagedCount ,
343
+ feed : feedDescriptor ,
331
344
} )
332
345
stats . engagedCount = 0
333
346
}
334
347
335
348
if ( stats . seenCount > 0 ) {
336
- logEvent ( 'discover :seen', {
349
+ logger . metric ( 'feed :seen', {
337
350
count : stats . seenCount ,
351
+ feed : feedDescriptor ,
338
352
} )
339
353
stats . seenCount = 0
340
354
}
0 commit comments