Fix up metrics and mutations

This commit is contained in:
Eric Bailey
2026-01-14 09:05:39 -06:00
parent 981bd2ff3d
commit 26399b27d0
12 changed files with 126 additions and 42 deletions
@@ -50,7 +50,7 @@ export function DiscoverFeedLiveEventFeedsAndTrendingBanner() {
<>
<View style={[a.px_lg, a.pt_md, a.pb_xs]}>
<View>
<LiveEventFeedCardWide feed={feed} />
<LiveEventFeedCardWide feed={feed} metricContext="discover" />
<Button
label={_(msg`Configure live event banner`)}
@@ -88,7 +88,11 @@ export function DiscoverFeedLiveEventFeedsAndTrendingBanner() {
</View>
</View>
<LiveEventFeedOptionsMenu feed={feed} control={optionsMenuControl} />
<LiveEventFeedOptionsMenu
feed={feed}
control={optionsMenuControl}
metricContext="discover"
/>
</>
)
}
@@ -11,7 +11,7 @@ export function ExploreScreenLiveEventFeedsBanner() {
if (!feed) return null
return (
<View style={[a.p_lg, a.border_b, t.atoms.border_contrast_low]}>
<LiveEventFeedCardWide feed={feed} />
<LiveEventFeedCardWide feed={feed} metricContext="explore" />
</View>
)
}
@@ -6,14 +6,24 @@ import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {isBskyCustomFeedUrl} from '#/lib/strings/url-helpers'
import {logger} from '#/logger'
import {atoms as a, useBreakpoints, utils} from '#/alf'
import {Link} from '#/components/Link'
import {Text} from '#/components/Typography'
import {type LiveEventFeed} from '#/features/liveEvents/types'
import {
type LiveEventFeed,
type LiveEventFeedMetricContext,
} from '#/features/liveEvents/types'
const roundedStyles = [a.rounded_lg, a.curve_continuous]
export function LiveEventFeedCardWide({feed}: {feed: LiveEventFeed}) {
export function LiveEventFeedCardWide({
feed,
metricContext,
}: {
feed: LiveEventFeed
metricContext: LiveEventFeedMetricContext
}) {
const {_} = useLingui()
const {gtPhone} = useBreakpoints()
@@ -30,7 +40,13 @@ export function LiveEventFeedCardWide({feed}: {feed: LiveEventFeed}) {
<Link
to={url}
label={_(msg`Live event happening now: ${feed.title}`)}
style={[a.w_full]}>
style={[a.w_full]}
onPress={() => {
logger.metric('liveEvents:feed:click', {
feed: feed.url,
context: metricContext,
})
}}>
{({hovered, pressed}) => (
<View style={[roundedStyles, a.shadow_md, a.w_full]}>
<View
@@ -16,16 +16,21 @@ import {
type LiveEventPreferencesAction,
useUpdateLiveEventPreferences,
} from '#/features/liveEvents/preferences'
import {type LiveEventFeed} from '#/features/liveEvents/types'
import {
type LiveEventFeed,
type LiveEventFeedMetricContext,
} from '#/features/liveEvents/types'
export {useDialogControl} from '#/components/Dialog'
export function LiveEventFeedOptionsMenu({
control,
feed,
metricContext,
}: {
control: Dialog.DialogControlProps
feed: LiveEventFeed
metricContext: LiveEventFeedMetricContext
}) {
const {_} = useLingui()
return (
@@ -34,7 +39,7 @@ export function LiveEventFeedOptionsMenu({
<Dialog.ScrollableInner
label={_(msg`Configure live event banner`)}
style={[web({maxWidth: 400})]}>
<Inner control={control} feed={feed} />
<Inner control={control} feed={feed} metricContext={metricContext} />
<Dialog.Close />
</Dialog.ScrollableInner>
</Dialog.Outer>
@@ -44,9 +49,11 @@ export function LiveEventFeedOptionsMenu({
function Inner({
control,
feed,
metricContext,
}: {
control: Dialog.DialogControlProps
feed: LiveEventFeed
metricContext: LiveEventFeedMetricContext
}) {
const {_} = useLingui()
const canUndo = useRef(true)
@@ -57,6 +64,8 @@ function Inner({
error: rawError,
variables,
} = useUpdateLiveEventPreferences({
feed,
metricContext,
onSuccess() {
toast.show(
<toast.Outer>
@@ -16,7 +16,9 @@ export function LiveEventFeedsSettingsToggle() {
isPending,
data: updatedPrefs,
mutate: update,
} = useUpdateLiveEventPreferences()
} = useUpdateLiveEventPreferences({
metricContext: 'settings',
})
const hideAllFeeds = !!(updatedPrefs || prefs)?.hideAllFeeds
return (
+33 -8
View File
@@ -9,6 +9,11 @@ import {
usePreferencesQuery,
} from '#/state/queries/preferences'
import {useAgent} from '#/state/session'
import * as env from '#/env'
import {
type LiveEventFeed,
type LiveEventFeedMetricContext,
} from '#/features/liveEvents/types'
export type LiveEventPreferencesAction = Parameters<
Agent['updateLiveEventPreferences']
@@ -46,7 +51,9 @@ function useWebOnlyDebugLiveEventPreferences() {
}, [agent, queryClient])
}
export function useUpdateLiveEventPreferences(props?: {
export function useUpdateLiveEventPreferences(props: {
feed?: LiveEventFeed
metricContext: LiveEventFeedMetricContext
onSuccess?: () => void
onError?: (error: Error) => void
}) {
@@ -64,19 +71,37 @@ export function useUpdateLiveEventPreferences(props?: {
const updated = await agent.updateLiveEventPreferences(action)
switch (action.type) {
case 'hideFeed': {
logger.metric('liveEventFeeds:hideFeed', {feedId: action.id})
break
}
case 'hideFeed':
case 'unhideFeed': {
logger.metric('liveEventFeeds:unhideFeed', {feedId: action.id})
if (!props.feed) {
if (env.IS_DEV) {
throw new Error(
'props.feed is required when calling hideFeed or unhideFeed',
)
}
break
}
logger.metric(
action.type === 'hideFeed'
? 'liveEvents:feed:hide'
: 'liveEvents:feed:unhide',
{
feed: props.feed.url,
context: props.metricContext,
},
)
break
}
case 'toggleHideAllFeeds': {
if (updated!.hideAllFeeds) {
logger.metric('liveEventFeed:hideAllFeeds', {})
logger.metric('liveEvents:hideAllFeeds', {
context: props.metricContext,
})
} else {
logger.metric('liveEventFeed:unhideAllFeeds', {})
logger.metric('liveEvents:unhideAllFeeds', {
context: props.metricContext,
})
}
break
}
+7
View File
@@ -10,6 +10,7 @@ export type LiveEventFeedImage = {
export type LiveEventFeed = {
id: string
preview: boolean
title: string
url: string
images: Record<LiveEventFeedImageLayout, LiveEventFeedImage>
@@ -18,3 +19,9 @@ export type LiveEventFeed = {
export type LiveEventsWorkerResponse = {
feeds: LiveEventFeed[]
}
export type LiveEventFeedMetricContext =
| 'explore'
| 'discover'
| 'sidebar'
| 'settings'
+2
View File
@@ -16,6 +16,8 @@ import {enabledLogLevels} from '#/logger/util'
import {isNative} from '#/platform/detection'
import {ENV} from '#/env'
export {type MetricEvents as Metrics} from '#/logger/metrics'
const TRANSPORTS: Transport[] = (function configureTransports() {
switch (ENV) {
case 'production': {
+19 -4
View File
@@ -1,5 +1,6 @@
import {type NotificationReason} from '#/lib/hooks/useNotificationHandler'
import {type FeedDescriptor} from '#/state/queries/post-feed'
import {type LiveEventFeedMetricContext} from '#/features/liveEvents/types'
export type MetricEvents = {
// App events
@@ -789,8 +790,22 @@ export type MetricEvents = {
// user pressed the remove all data button
'contacts:settings:removeData': {}
'liveEventFeeds:hideFeed': {feedId: string}
'liveEventFeeds:unhideFeed': {feedId: string}
'liveEventFeed:hideAllFeeds': {}
'liveEventFeed:unhideAllFeeds': {}
'liveEvents:feed:click': {
feed: string
context: LiveEventFeedMetricContext
}
'liveEvents:feed:hide': {
feed: string
context: LiveEventFeedMetricContext
}
'liveEvents:feed:unhide': {
feed: string
context: LiveEventFeedMetricContext
}
'liveEvents:hideAllFeeds': {
context: LiveEventFeedMetricContext
}
'liveEvents:unhideAllFeeds': {
context: LiveEventFeedMetricContext
}
}
+4
View File
@@ -45,4 +45,8 @@ export const DEFAULT_LOGGED_OUT_PREFERENCES: UsePreferencesQueryResponse = {
verificationPrefs: {
hideBadges: false,
},
liveEventPreferences: {
hideAllFeeds: false,
hiddenFeedIds: [],
},
}