[APP-1782] Analytics migration (#9734)

* WIP

* Clean up growthbook code, integrate into init and sessions

* Move everything out of React

* Add metrics client

* Move to separate file

* Shared metadata cache

* Ensure we update metadata when session ID changes

* Ensure userMetadata is cleared when logging out

* WIP revamp

* Integrate feature gates into analytics context

* Clean up old code

* Fix useMeta util

* Some comments and cleanup

* Add logger to base analytics context

* Refactor current route handling

* Rip out LogEvent from navigation

* Update tracking endpoint

* Migrate toClout

* Clear out statsig client

* Add todo, reset logger readme

* Ope fix statsig noop

* Refactor logging in feed-feedback, add debug logging to metrics client

* Remove LogEvents alias for Metrics

* Prefer root package export

* Remove Metrics alias from logger

* [APP-1782] Migrate to new analytics APIs (#9735)

* Migrate logEvent to useAnalytics

* Migrate logger.metric to useAnalytics

* Migrate tricky spot, fix types

* Migrate remaining tricky spot

* Missed one

* Remove metric() from logger

* Migrate useGate to useAnalytics

* Remove all other StatSig mentions

* Update event payload

* Update logger tests

* Mock expo method

* Fix session ID bug

* Add session ID test

* Add test for metrics client

* Clarify intent

* Clean up core analytics file

* Clean up the call once utils

* Fix TODO

* Fix TODO

* Fix TODO

* Fix TODO

* Fix TODO

* Remove debug code

* Fix navigation context

* OK nav context is not working, todo

* Checkpoint: works but feels hacky

* Fix navigation context issue

* Improve feature API

* Improve metric logging

* Update logger tests
This commit is contained in:
Eric Bailey
2026-01-22 15:33:45 -06:00
committed by GitHub
parent 8614e5e105
commit 25a1ed1209
190 changed files with 2358 additions and 1689 deletions
@@ -6,8 +6,8 @@ import {useLingui} from '@lingui/react'
import {wait} from '#/lib/async/wait'
import {getLabelingServiceTitle} from '#/lib/moderation'
import {useCallOnce} from '#/lib/once'
import {sanitizeHandle} from '#/lib/strings/handles'
import {Logger} from '#/logger'
import {useMyLabelersQuery} from '#/state/queries/preferences'
import {CharProgress} from '#/view/com/composer/char-progress/CharProgress'
import {UserAvatar} from '#/view/com/util/UserAvatar'
@@ -28,6 +28,7 @@ import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times'
import {createStaticClick, InlineLinkText, Link} from '#/components/Link'
import {Loader} from '#/components/Loader'
import {Text} from '#/components/Typography'
import {useAnalytics} from '#/analytics'
import {IS_NATIVE} from '#/env'
import {useSubmitReportMutation} from './action'
import {
@@ -53,8 +54,6 @@ export function useGlobalReportDialogControl() {
return useGlobalDialogsControlContext().reportDialogControl
}
const logger = Logger.create(Logger.Context.ReportDialog)
export function GlobalReportDialog() {
const {value, control} = useGlobalReportDialogControl()
return <ReportDialog control={control} subject={value?.subject} />
@@ -65,13 +64,14 @@ export function ReportDialog(
subject?: ReportSubject
},
) {
const ax = useAnalytics()
const subject = React.useMemo(
() => (props.subject ? parseReportSubject(props.subject) : undefined),
[props.subject],
)
const onClose = React.useCallback(() => {
logger.metric('reportDialog:close', {}, {statsig: false})
}, [])
ax.metric('reportDialog:close', {})
}, [ax])
return (
<Dialog.Outer control={props.control} onClose={onClose}>
<Dialog.Handle />
@@ -103,6 +103,8 @@ function Invalid() {
}
function Inner(props: ReportDialogProps) {
const ax = useAnalytics()
const logger = ax.logger.useChild(ax.logger.Context.ReportDialog)
const t = useTheme()
const {_} = useLingui()
const ref = React.useRef<ScrollView>(null)
@@ -208,15 +210,11 @@ function Inner(props: ReportDialogProps) {
}),
)
setSuccess(true)
logger.metric(
'reportDialog:success',
{
reason: state.selectedOption?.reason ?? '',
labeler: state.selectedLabeler?.creator.handle ?? '',
details: !!state.details,
},
{statsig: false},
)
ax.metric('reportDialog:success', {
reason: state.selectedOption?.reason ?? '',
labeler: state.selectedLabeler?.creator.handle ?? '',
details: !!state.details,
})
// give time for user feedback
setTimeout(() => {
props.control.close(() => {
@@ -224,7 +222,7 @@ function Inner(props: ReportDialogProps) {
})
}, 1e3)
} catch (e: any) {
logger.metric('reportDialog:failure', {}, {statsig: false})
ax.metric('reportDialog:failure', {})
logger.error(e, {
source: 'ReportDialog',
})
@@ -237,15 +235,11 @@ function Inner(props: ReportDialogProps) {
}
}, [_, submitReport, state, dispatch, props, setPending, setSuccess])
React.useEffect(() => {
logger.metric(
'reportDialog:open',
{
subjectType: props.subject.type,
},
{statsig: false},
)
}, [props.subject])
useCallOnce(() => {
ax.metric('reportDialog:open', {
subjectType: props.subject.type,
})
})()
return (
<Dialog.ScrollableInner