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

@ -6,9 +6,8 @@ import {
} from '@segment/analytics-react'
import {sha256} from 'js-sha256'
import {useSession} from '#/state/session'
import {useSession, SessionAccount} from '#/state/session'
import {logger} from '#/logger'
import {listenSessionLoaded} from '#/state/events'
const segmentClient = createClient(
{
@ -44,8 +43,8 @@ export function useAnalytics() {
}, [hasSession, methods])
}
export function init() {
listenSessionLoaded(account => {
export function init(account: SessionAccount | undefined) {
if (account) {
if (account.did) {
if (account.did) {
const did_hashed = sha256(account.did)
@ -56,7 +55,7 @@ export function init() {
segmentClient.identify()
}
}
})
}
}
export function Provider({children}: React.PropsWithChildren<{}>) {