An ATproto social media client -- with an independent Appview.

Fix feedfeedback metrics not distinguishing which feed it's from (#9099)

* fix feedfeedback metrics being sent for all feeds

* remove `discover:` metrics

authored by samuel.fm and committed by GitHub 1e6a44f2 144d61ef

Changed files
+36 -17
src
+10 -5
src/logger/metrics.ts
··· 175 175 'feed:suggestion:press': { 176 176 feedUrl: string 177 177 } 178 - 'discover:showMore': { 178 + 'feed:showMore': { 179 + feed: string 179 180 feedContext: string 180 181 } 181 - 'discover:showLess': { 182 + 'feed:showLess': { 183 + feed: string 182 184 feedContext: string 183 185 } 184 - 'discover:clickthrough': { 186 + 'feed:clickthrough': { 187 + feed: string 185 188 count: number 186 189 } 187 - 'discover:engaged': { 190 + 'feed:engaged': { 191 + feed: string 188 192 count: number 189 193 } 190 - 'discover:seen': { 194 + 'feed:seen': { 195 + feed: string 191 196 count: number 192 197 } 193 198
+26 -12
src/state/feed-feedback.tsx
··· 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 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 142 sendOrAggregateInteractionsForStats( 136 143 aggregatedStats.current, 137 144 interactionsToSend, 145 + feed?.feedDescriptor ?? 'unknown', 138 146 ) 139 147 throttledFlushAggregatedStats() 140 148 logger.debug('flushed') ··· 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 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 }