diff options
author | Eric Bailey <git@esb.lol> | 2023-11-15 19:37:55 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-15 17:37:55 -0800 |
commit | 952f5033d0c23dcd3723883a8f5c08ef779b7559 (patch) | |
tree | c293f22c59fb77d329ee70abbc8c058a8ec6ae64 | |
parent | 610eeecd26d604bdb10673307075e738168c4ebb (diff) | |
download | voidsky-952f5033d0c23dcd3723883a8f5c08ef779b7559.tar.zst |
Fixes analytics init on web (#1923)
-rw-r--r-- | src/lib/analytics/analytics.web.tsx | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/lib/analytics/analytics.web.tsx b/src/lib/analytics/analytics.web.tsx index fe90d1328..0a5d5d689 100644 --- a/src/lib/analytics/analytics.web.tsx +++ b/src/lib/analytics/analytics.web.tsx @@ -4,10 +4,11 @@ import { AnalyticsProvider, useAnalytics as useAnalyticsOrig, } from '@segment/analytics-react' -import {RootStoreModel} from 'state/models/root-store' -import {useStores} from 'state/models/root-store' import {sha256} from 'js-sha256' + +import {useSession} from '#/state/session' import {logger} from '#/logger' +import {listenSessionLoaded} from '#/state/events' const segmentClient = createClient( { @@ -24,10 +25,10 @@ const segmentClient = createClient( export const track = segmentClient?.track?.bind?.(segmentClient) export function useAnalytics() { - const store = useStores() + const {hasSession} = useSession() const methods = useAnalyticsOrig() return React.useMemo(() => { - if (store.session.hasSession) { + if (hasSession) { return methods } // dont send analytics pings for anonymous users @@ -40,15 +41,14 @@ export function useAnalytics() { alias: () => {}, reset: () => {}, } - }, [store, methods]) + }, [hasSession, methods]) } -export function init(store: RootStoreModel) { - store.onSessionLoaded(() => { - const sess = store.session.currentSession - if (sess) { - if (sess.did) { - const did_hashed = sha256(sess.did) +export function init() { + listenSessionLoaded(account => { + if (account.did) { + if (account.did) { + const did_hashed = sha256(account.did) segmentClient.identify(did_hashed, {did_hashed}) logger.debug('Ping w/hash') } else { |