Some metrics

This commit is contained in:
Eric Bailey
2025-06-10 10:05:04 -05:00
parent ae329bd733
commit 5b7f34a1d5
4 changed files with 50 additions and 1 deletions
+20
View File
@@ -0,0 +1,20 @@
import {useCallback} from 'react'
export enum OnceKey {
PreferencesThread = 'preferences:thread',
}
const called: Record<OnceKey, boolean> = {
[OnceKey.PreferencesThread]: false,
}
export function useCallOnce(key: OnceKey) {
return useCallback(
(cb: () => void) => {
if (called[key] === true) return
called[key] = true
cb()
},
[key],
)
}
+8
View File
@@ -434,4 +434,12 @@ export type MetricEvents = {
'share:press:dmSelected': {} 'share:press:dmSelected': {}
'share:press:recentDm': {} 'share:press:recentDm': {}
'share:press:embed': {} 'share:press:embed': {}
'thread:click:showOtherReplies': {}
'thread:preferences:load': {
[key: string]: any
}
'thread:preferences:update': {
[key: string]: any
}
} }
@@ -2,6 +2,7 @@ import {View} from 'react-native'
import {msg} from '@lingui/macro' import {msg} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {logger} from '#/logger'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {Button} from '#/components/Button' import {Button} from '#/components/Button'
import {EyeSlash_Stroke2_Corner0_Rounded as EyeSlash} from '#/components/icons/EyeSlash' import {EyeSlash_Stroke2_Corner0_Rounded as EyeSlash} from '#/components/icons/EyeSlash'
@@ -13,7 +14,12 @@ export function ThreadItemShowOtherReplies({onPress}: {onPress: () => void}) {
const label = _(msg`Show more replies`) const label = _(msg`Show more replies`)
return ( return (
<Button onPress={onPress} label={label}> <Button
onPress={() => {
onPress()
logger.metric('thread:click:showOtherReplies', {})
}}
label={label}>
{({hovered, pressed}) => ( {({hovered, pressed}) => (
<View <View
style={[ style={[
@@ -2,6 +2,7 @@ import {useCallback, useMemo, useRef, useState} from 'react'
import {type AppBskyUnspeccedGetPostThreadV2} from '@atproto/api' import {type AppBskyUnspeccedGetPostThreadV2} from '@atproto/api'
import debounce from 'lodash.debounce' import debounce from 'lodash.debounce'
import {OnceKey,useCallOnce} from '#/lib/hooks/useCallOnce'
import {logger} from '#/logger' import {logger} from '#/logger'
import { import {
usePreferencesQuery, usePreferencesQuery,
@@ -31,6 +32,7 @@ export function useThreadPreferences({
}: {save?: boolean} = {}): ThreadPreferences { }: {save?: boolean} = {}): ThreadPreferences {
const {data: preferences} = usePreferencesQuery() const {data: preferences} = usePreferencesQuery()
const serverPrefs = preferences?.threadViewPrefs const serverPrefs = preferences?.threadViewPrefs
const once = useCallOnce(OnceKey.PreferencesThread)
/* /*
* Create local state representations of server state * Create local state representations of server state
@@ -63,6 +65,14 @@ export function useThreadPreferences({
treeViewEnabled: !!serverPrefs.lab_treeViewEnabled, treeViewEnabled: !!serverPrefs.lab_treeViewEnabled,
}), }),
) )
once(() => {
logger.metric('thread:preferences:load', {
sort: serverPrefs.sort,
view: serverPrefs.lab_treeViewEnabled ? 'tree' : 'linear',
prioritizeFollowedUsers: serverPrefs.prioritizeFollowedUsers,
})
})
} }
const userUpdatedPrefs = useRef(false) const userUpdatedPrefs = useRef(false)
@@ -73,6 +83,11 @@ export function useThreadPreferences({
try { try {
setIsSaving(true) setIsSaving(true)
await mutateAsync(prefs) await mutateAsync(prefs)
logger.metric('thread:preferences:update', {
sort: prefs.sort,
view: prefs.lab_treeViewEnabled ? 'tree' : 'linear',
prioritizeFollowedUsers: prefs.prioritizeFollowedUsers,
})
} catch (e) { } catch (e) {
logger.error('useThreadPreferences failed to save', { logger.error('useThreadPreferences failed to save', {
safeMessage: e, safeMessage: e,