[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:
@@ -9,7 +9,6 @@ import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||
import {PROD_DEFAULT_FEED} from '#/lib/constants'
|
||||
import {replaceEqualDeep} from '#/lib/functions'
|
||||
import {getAge} from '#/lib/strings/time'
|
||||
import {logger} from '#/logger'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {
|
||||
DEFAULT_HOME_FEED_PREFS,
|
||||
@@ -24,6 +23,7 @@ import {useAgent} from '#/state/session'
|
||||
import {saveLabelers} from '#/state/session/agent-config'
|
||||
import {useAgeAssurance} from '#/ageAssurance'
|
||||
import {makeAgeRestrictedModerationPrefs} from '#/ageAssurance/util'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
|
||||
export * from '#/state/queries/preferences/const'
|
||||
export * from '#/state/queries/preferences/moderation'
|
||||
@@ -110,6 +110,7 @@ export function useClearPreferencesMutation() {
|
||||
}
|
||||
|
||||
export function usePreferencesSetContentLabelMutation() {
|
||||
const ax = useAnalytics()
|
||||
const agent = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
@@ -120,11 +121,7 @@ export function usePreferencesSetContentLabelMutation() {
|
||||
>({
|
||||
mutationFn: async ({label, visibility, labelerDid}) => {
|
||||
await agent.setContentLabelPref(label, visibility, labelerDid)
|
||||
logger.metric(
|
||||
'moderation:changeLabelPreference',
|
||||
{preference: visibility},
|
||||
{statsig: true},
|
||||
)
|
||||
ax.metric('moderation:changeLabelPreference', {preference: visibility})
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
queryKey: preferencesQueryKey,
|
||||
@@ -417,6 +414,7 @@ export function useSetActiveProgressGuideMutation() {
|
||||
}
|
||||
|
||||
export function useSetVerificationPrefsMutation() {
|
||||
const ax = useAnalytics()
|
||||
const queryClient = useQueryClient()
|
||||
const agent = useAgent()
|
||||
|
||||
@@ -424,9 +422,9 @@ export function useSetVerificationPrefsMutation() {
|
||||
mutationFn: async prefs => {
|
||||
await agent.setVerificationPrefs(prefs)
|
||||
if (prefs.hideBadges) {
|
||||
logger.metric('verification:settings:hideBadges', {}, {statsig: true})
|
||||
ax.metric('verification:settings:hideBadges', {})
|
||||
} else {
|
||||
logger.metric('verification:settings:unHideBadges', {}, {statsig: true})
|
||||
ax.metric('verification:settings:unHideBadges', {})
|
||||
}
|
||||
// triggers a refetch
|
||||
await queryClient.invalidateQueries({
|
||||
|
||||
@@ -2,13 +2,13 @@ import {useCallback, useMemo, useRef, useState} from 'react'
|
||||
import {type AppBskyUnspeccedGetPostThreadV2} from '@atproto/api'
|
||||
import debounce from 'lodash.debounce'
|
||||
|
||||
import {OnceKey, useCallOnce} from '#/lib/hooks/useCallOnce'
|
||||
import {logger} from '#/logger'
|
||||
import {useCallOnce} from '#/lib/once'
|
||||
import {
|
||||
usePreferencesQuery,
|
||||
useSetThreadViewPreferencesMutation,
|
||||
} from '#/state/queries/preferences'
|
||||
import {type ThreadViewPreferences} from '#/state/queries/preferences/types'
|
||||
import {useAnalytics} from '#/analytics'
|
||||
import {type Literal} from '#/types/utils'
|
||||
|
||||
export type ThreadSortOption = Literal<
|
||||
@@ -28,9 +28,10 @@ export type ThreadPreferences = {
|
||||
export function useThreadPreferences({
|
||||
save,
|
||||
}: {save?: boolean} = {}): ThreadPreferences {
|
||||
const ax = useAnalytics()
|
||||
const {data: preferences} = usePreferencesQuery()
|
||||
const serverPrefs = preferences?.threadViewPrefs
|
||||
const once = useCallOnce(OnceKey.PreferencesThread)
|
||||
const once = useCallOnce()
|
||||
|
||||
/*
|
||||
* Create local state representations of server state
|
||||
@@ -61,7 +62,7 @@ export function useThreadPreferences({
|
||||
)
|
||||
|
||||
once(() => {
|
||||
logger.metric('thread:preferences:load', {
|
||||
ax.metric('thread:preferences:load', {
|
||||
sort: serverPrefs.sort,
|
||||
view: serverPrefs.lab_treeViewEnabled ? 'tree' : 'linear',
|
||||
})
|
||||
@@ -76,12 +77,12 @@ export function useThreadPreferences({
|
||||
try {
|
||||
setIsSaving(true)
|
||||
await mutateAsync(prefs)
|
||||
logger.metric('thread:preferences:update', {
|
||||
ax.metric('thread:preferences:update', {
|
||||
sort: prefs.sort,
|
||||
view: prefs.lab_treeViewEnabled ? 'tree' : 'linear',
|
||||
})
|
||||
} catch (e) {
|
||||
logger.error('useThreadPreferences failed to save', {
|
||||
ax.logger.error('useThreadPreferences failed to save', {
|
||||
safeMessage: e,
|
||||
})
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user