[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
+12 -14
View File
@@ -12,6 +12,7 @@ import {useResolveDidQuery} from '#/state/queries/resolve-uri'
import {useSession} from '#/state/session'
import {PeopleRemove2_Stroke1_Corner0_Rounded as PeopleRemoveIcon} from '#/components/icons/PeopleRemove2'
import {ListFooter, ListMaybePlaceholder} from '#/components/Lists'
import {useAnalytics} from '#/analytics'
import {List} from '../util/List'
import {ProfileCardWithFollowBtn} from './ProfileCard'
@@ -41,6 +42,7 @@ function keyExtractor(item: ActorDefs.ProfileViewBasic) {
export function ProfileFollowers({name}: {name: string}) {
const {_} = useLingui()
const ax = useAnalytics()
const navigation = useNavigation()
const initialNumToRender = useInitialNumToRender()
const {currentAccount} = useSession()
@@ -88,14 +90,14 @@ export function ProfileFollowers({name}: {name: string}) {
currentPageCount >= 3 &&
currentPageCount > paginationTrackingRef.current.page
) {
logger.metric('profile:followers:paginate', {
ax.metric('profile:followers:paginate', {
contextProfileDid: resolvedDid,
itemCount: followers.length,
page: currentPageCount,
})
}
paginationTrackingRef.current.page = currentPageCount
}, [data?.pages?.length, resolvedDid, followers.length])
}, [ax, data?.pages?.length, resolvedDid, followers.length])
const onRefresh = React.useCallback(async () => {
setIsPTRing(true)
@@ -125,12 +127,12 @@ export function ProfileFollowers({name}: {name: string}) {
// track pageview
React.useEffect(() => {
if (resolvedDid) {
logger.metric('profile:followers:view', {
ax.metric('profile:followers:view', {
contextProfileDid: resolvedDid,
isOwnProfile: isMe,
})
}
}, [resolvedDid, isMe])
}, [ax, resolvedDid, isMe])
// track seen items
const seenItemsRef = React.useRef<Set<string>>(new Set())
@@ -147,17 +149,13 @@ export function ProfileFollowers({name}: {name: string}) {
if (position === 0) {
return
}
logger.metric(
'profileCard:seen',
{
profileDid: item.did,
position,
...(resolvedDid !== undefined && {contextProfileDid: resolvedDid}),
},
{statsig: false},
)
ax.metric('profileCard:seen', {
profileDid: item.did,
position,
...(resolvedDid !== undefined && {contextProfileDid: resolvedDid}),
})
},
[followers, resolvedDid],
[ax, followers, resolvedDid],
)
if (followers.length < 1) {
+12 -14
View File
@@ -14,6 +14,7 @@ import {useSession} from '#/state/session'
import {FindContactsBannerNUX} from '#/components/contacts/FindContactsBannerNUX'
import {PeopleRemove2_Stroke1_Corner0_Rounded as PeopleRemoveIcon} from '#/components/icons/PeopleRemove2'
import {ListFooter, ListMaybePlaceholder} from '#/components/Lists'
import {useAnalytics} from '#/analytics'
import {IS_WEB} from '#/env'
import {List} from '../util/List'
import {ProfileCardWithFollowBtn} from './ProfileCard'
@@ -44,6 +45,7 @@ function keyExtractor(item: ActorDefs.ProfileViewBasic) {
export function ProfileFollows({name}: {name: string}) {
const {_} = useLingui()
const ax = useAnalytics()
const initialNumToRender = useInitialNumToRender()
const {currentAccount} = useSession()
const navigation = useNavigation<NavigationProp>()
@@ -100,14 +102,14 @@ export function ProfileFollows({name}: {name: string}) {
currentPageCount >= 3 &&
currentPageCount > paginationTrackingRef.current.page
) {
logger.metric('profile:following:paginate', {
ax.metric('profile:following:paginate', {
contextProfileDid: resolvedDid,
itemCount: follows.length,
page: currentPageCount,
})
}
paginationTrackingRef.current.page = currentPageCount
}, [data?.pages?.length, resolvedDid, follows.length])
}, [ax, data?.pages?.length, resolvedDid, follows.length])
const onRefresh = React.useCallback(async () => {
setIsPTRing(true)
@@ -137,12 +139,12 @@ export function ProfileFollows({name}: {name: string}) {
// track pageview
React.useEffect(() => {
if (resolvedDid) {
logger.metric('profile:following:view', {
ax.metric('profile:following:view', {
contextProfileDid: resolvedDid,
isOwnProfile: isMe,
})
}
}, [resolvedDid, isMe])
}, [ax, resolvedDid, isMe])
// track seen items
const seenItemsRef = React.useRef<Set<string>>(new Set())
@@ -159,17 +161,13 @@ export function ProfileFollows({name}: {name: string}) {
if (position === 0) {
return
}
logger.metric(
'profileCard:seen',
{
profileDid: item.did,
position,
...(resolvedDid !== undefined && {contextProfileDid: resolvedDid}),
},
{statsig: false},
)
ax.metric('profileCard:seen', {
profileDid: item.did,
position,
...(resolvedDid !== undefined && {contextProfileDid: resolvedDid}),
})
},
[follows, resolvedDid],
[ax, follows, resolvedDid],
)
if (follows.length < 1) {
+13 -12
View File
@@ -11,7 +11,6 @@ import {makeProfileLink} from '#/lib/routes/links'
import {type NavigationProp} from '#/lib/routes/types'
import {shareText, shareUrl} from '#/lib/sharing'
import {toShareUrl} from '#/lib/strings/url-helpers'
import {logger} from '#/logger'
import {type Shadow} from '#/state/cache/types'
import {useModalControls} from '#/state/modals'
import {Nux, useNux, useSaveNux} from '#/state/queries/nuxs'
@@ -60,6 +59,7 @@ import * as Prompt from '#/components/Prompt'
import {useFullVerificationState} from '#/components/verification'
import {VerificationCreatePrompt} from '#/components/verification/VerificationCreatePrompt'
import {VerificationRemovePrompt} from '#/components/verification/VerificationRemovePrompt'
import {useAnalytics} from '#/analytics'
import {IS_WEB} from '#/env'
import {Dot} from '#/features/nuxs/components/Dot'
import {Gradient} from '#/features/nuxs/components/Gradient'
@@ -71,6 +71,7 @@ let ProfileMenu = ({
profile: Shadow<AppBskyActorDefs.ProfileViewDetailed>
}): React.ReactNode => {
const t = useTheme()
const ax = useAnalytics()
const {_} = useLingui()
const {currentAccount, hasSession} = useSession()
const {openModal} = useModalControls()
@@ -121,7 +122,7 @@ let ProfileMenu = ({
}, [queryClient, profile.did])
const onPressAddToStarterPacks = React.useCallback(() => {
logger.metric('profile:addToStarterPack', {})
ax.metric('profile:addToStarterPack', {})
addToStarterPacksDialogControl.open()
}, [addToStarterPacksDialogControl])
@@ -147,7 +148,7 @@ let ProfileMenu = ({
Toast.show(_(msg({message: 'Account unmuted', context: 'toast'})))
} catch (e: any) {
if (e?.name !== 'AbortError') {
logger.error('Failed to unmute account', {message: e})
ax.logger.error('Failed to unmute account', {message: e})
Toast.show(_(msg`There was an issue! ${e.toString()}`), 'xmark')
}
}
@@ -157,12 +158,12 @@ let ProfileMenu = ({
Toast.show(_(msg({message: 'Account muted', context: 'toast'})))
} catch (e: any) {
if (e?.name !== 'AbortError') {
logger.error('Failed to mute account', {message: e})
ax.logger.error('Failed to mute account', {message: e})
Toast.show(_(msg`There was an issue! ${e.toString()}`), 'xmark')
}
}
}
}, [profile.viewer?.muted, queueUnmute, _, queueMute])
}, [ax, profile.viewer?.muted, queueUnmute, _, queueMute])
const blockAccount = React.useCallback(async () => {
if (profile.viewer?.blocking) {
@@ -171,7 +172,7 @@ let ProfileMenu = ({
Toast.show(_(msg({message: 'Account unblocked', context: 'toast'})))
} catch (e: any) {
if (e?.name !== 'AbortError') {
logger.error('Failed to unblock account', {message: e})
ax.logger.error('Failed to unblock account', {message: e})
Toast.show(_(msg`There was an issue! ${e.toString()}`), 'xmark')
}
}
@@ -181,12 +182,12 @@ let ProfileMenu = ({
Toast.show(_(msg({message: 'Account blocked', context: 'toast'})))
} catch (e: any) {
if (e?.name !== 'AbortError') {
logger.error('Failed to block account', {message: e})
ax.logger.error('Failed to block account', {message: e})
Toast.show(_(msg`There was an issue! ${e.toString()}`), 'xmark')
}
}
}
}, [profile.viewer?.blocking, _, queueUnblock, queueBlock])
}, [ax, profile.viewer?.blocking, _, queueUnblock, queueBlock])
const onPressFollowAccount = React.useCallback(async () => {
try {
@@ -194,11 +195,11 @@ let ProfileMenu = ({
Toast.show(_(msg({message: 'Account followed', context: 'toast'})))
} catch (e: any) {
if (e?.name !== 'AbortError') {
logger.error('Failed to follow account', {message: e})
ax.logger.error('Failed to follow account', {message: e})
Toast.show(_(msg`There was an issue! ${e.toString()}`), 'xmark')
}
}
}, [_, queueFollow])
}, [_, ax, queueFollow])
const onPressUnfollowAccount = React.useCallback(async () => {
try {
@@ -206,11 +207,11 @@ let ProfileMenu = ({
Toast.show(_(msg({message: 'Account unfollowed', context: 'toast'})))
} catch (e: any) {
if (e?.name !== 'AbortError') {
logger.error('Failed to unfollow account', {message: e})
ax.logger.error('Failed to unfollow account', {message: e})
Toast.show(_(msg`There was an issue! ${e.toString()}`), 'xmark')
}
}
}, [_, queueUnfollow])
}, [_, ax, queueUnfollow])
const onPressReportAccount = React.useCallback(() => {
reportDialogControl.open()