Skip to content

Commit 1e6a44f

Browse files
authored
Fix feedfeedback metrics not distinguishing which feed it's from (#9099)
* fix feedfeedback metrics being sent for all feeds * remove `discover:` metrics
1 parent 144d61e commit 1e6a44f

File tree

2 files changed

+36
-17
lines changed

2 files changed

+36
-17
lines changed

src/logger/metrics.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,24 @@ export type MetricEvents = {
175175
'feed:suggestion:press': {
176176
feedUrl: string
177177
}
178-
'discover:showMore': {
178+
'feed:showMore': {
179+
feed: string
179180
feedContext: string
180181
}
181-
'discover:showLess': {
182+
'feed:showLess': {
183+
feed: string
182184
feedContext: string
183185
}
184-
'discover:clickthrough': {
186+
'feed:clickthrough': {
187+
feed: string
185188
count: number
186189
}
187-
'discover:engaged': {
190+
'feed:engaged': {
191+
feed: string
188192
count: number
189193
}
190-
'discover:seen': {
194+
'feed:seen': {
195+
feed: string
191196
count: number
192197
}
193198

src/state/feed-feedback.tsx

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import throttle from 'lodash.throttle'
1212

1313
import {PROD_FEEDS, STAGING_FEEDS} from '#/lib/constants'
1414
import {isNetworkError} from '#/lib/hooks/useCleanError'
15-
import {logEvent} from '#/lib/statsig/statsig'
1615
import {Logger} from '#/logger'
1716
import {
1817
type FeedSourceFeedInfo,
@@ -90,11 +89,19 @@ export function useFeedFeedback(
9089
const aggregatedStats = useRef<AggregatedStats | null>(null)
9190
const throttledFlushAggregatedStats = useMemo(
9291
() =>
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],
98105
)
99106

100107
const sendToFeedNoDelay = useCallback(() => {
@@ -135,6 +142,7 @@ export function useFeedFeedback(
135142
sendOrAggregateInteractionsForStats(
136143
aggregatedStats.current,
137144
interactionsToSend,
145+
feed?.feedDescriptor ?? 'unknown',
138146
)
139147
throttledFlushAggregatedStats()
140148
logger.debug('flushed')
@@ -271,19 +279,22 @@ function createAggregatedStats(): AggregatedStats {
271279
function sendOrAggregateInteractionsForStats(
272280
stats: AggregatedStats,
273281
interactions: AppBskyFeedDefs.Interaction[],
282+
feed: string,
274283
) {
275284
for (let interaction of interactions) {
276285
switch (interaction.event) {
277286
// Pressing "Show more" / "Show less" is relatively uncommon so we won't aggregate them.
278287
// This lets us send the feed context together with them.
279288
case 'app.bsky.feed.defs#requestLess': {
280-
logEvent('discover:showLess', {
289+
logger.metric('feed:showLess', {
290+
feed,
281291
feedContext: interaction.feedContext ?? '',
282292
})
283293
break
284294
}
285295
case 'app.bsky.feed.defs#requestMore': {
286-
logEvent('discover:showMore', {
296+
logger.metric('feed:showMore', {
297+
feed,
287298
feedContext: interaction.feedContext ?? '',
288299
})
289300
break
@@ -313,28 +324,31 @@ function sendOrAggregateInteractionsForStats(
313324
}
314325
}
315326

316-
function flushToStatsig(stats: AggregatedStats | null) {
327+
function flushToStatsig(stats: AggregatedStats | null, feedDescriptor: string) {
317328
if (stats === null) {
318329
return
319330
}
320331

321332
if (stats.clickthroughCount > 0) {
322-
logEvent('discover:clickthrough', {
333+
logger.metric('feed:clickthrough', {
323334
count: stats.clickthroughCount,
335+
feed: feedDescriptor,
324336
})
325337
stats.clickthroughCount = 0
326338
}
327339

328340
if (stats.engagedCount > 0) {
329-
logEvent('discover:engaged', {
341+
logger.metric('feed:engaged', {
330342
count: stats.engagedCount,
343+
feed: feedDescriptor,
331344
})
332345
stats.engagedCount = 0
333346
}
334347

335348
if (stats.seenCount > 0) {
336-
logEvent('discover:seen', {
349+
logger.metric('feed:seen', {
337350
count: stats.seenCount,
351+
feed: feedDescriptor,
338352
})
339353
stats.seenCount = 0
340354
}

0 commit comments

Comments
 (0)