Move analytics out of init (#2115)

* Remove listenSessionLoaded from analytics

* Move analytics init call to navigation ready

* Remove zod dependency from analytics

* Mirror changes on the web

* Delete listenSessionLoaded

* Only set up listeners once
This commit is contained in:
dan 2023-12-06 20:04:05 +00:00 committed by GitHub
parent 748212e000
commit 6335be14e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 35 additions and 48 deletions

View file

@ -8,7 +8,7 @@ import {logger} from '#/logger'
import * as persisted from '#/state/persisted'
import {PUBLIC_BSKY_AGENT} from '#/state/queries'
import {IS_PROD} from '#/lib/constants'
import {emitSessionLoaded, emitSessionDropped} from '../events'
import {emitSessionDropped} from '../events'
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
import {useCloseAllActiveElements} from '#/state/util'
import {track} from '#/lib/analytics/analytics'
@ -210,7 +210,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
__globalAgent = agent
queryClient.clear()
upsertAccount(account)
emitSessionLoaded(account, agent)
logger.debug(
`session: created account`,
@ -262,7 +261,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
__globalAgent = agent
queryClient.clear()
upsertAccount(account)
emitSessionLoaded(account, agent)
logger.debug(
`session: logged in`,
@ -355,12 +353,11 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
__globalAgent = agent
queryClient.clear()
upsertAccount(account)
emitSessionLoaded(account, agent)
// Intentionally not awaited to unblock the UI:
resumeSessionWithFreshAccount().then(async freshAccount => {
resumeSessionWithFreshAccount().then(freshAccount => {
if (JSON.stringify(account) !== JSON.stringify(freshAccount)) {
upsertAccount(freshAccount)
emitSessionLoaded(freshAccount, agent)
}
})
} else {
@ -368,7 +365,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
__globalAgent = agent
queryClient.clear()
upsertAccount(freshAccount)
emitSessionLoaded(freshAccount, agent)
}
async function resumeSessionWithFreshAccount(): Promise<SessionAccount> {