diff options
author | Hailey <me@haileyok.com> | 2024-09-27 14:01:57 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-27 14:01:57 -0700 |
commit | f68b15219fd02e23d965015201400138ed69d59d (patch) | |
tree | 1134642fff8db10b2cfca827a6c0d9cd2a4dbd5b /src/lib/analytics/analytics.web.tsx | |
parent | bcd096b85aee45c38de7cfbcf1115b0a544589ae (diff) | |
download | voidsky-f68b15219fd02e23d965015201400138ed69d59d.tar.zst |
Remove Segment (#5518)
Diffstat (limited to 'src/lib/analytics/analytics.web.tsx')
-rw-r--r-- | src/lib/analytics/analytics.web.tsx | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/src/lib/analytics/analytics.web.tsx b/src/lib/analytics/analytics.web.tsx deleted file mode 100644 index c7f0ed3b1..000000000 --- a/src/lib/analytics/analytics.web.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import React from 'react' -import {createClient} from '@segment/analytics-react' -import * as Sentry from '@sentry/react-native' -import {sha256} from 'js-sha256' - -import {logger} from '#/logger' -import {SessionAccount, useSession} from '#/state/session' -import {ScreenPropertiesMap, TrackPropertiesMap} from './types' - -type SegmentClient = ReturnType<typeof createClient> - -// Delay creating until first actual use. -let segmentClient: SegmentClient | null = null -function getClient(): SegmentClient { - if (!segmentClient) { - segmentClient = createClient( - { - writeKey: '8I6DsgfiSLuoONyaunGoiQM7A6y2ybdI', - }, - { - integrations: { - 'Segment.io': { - apiHost: 'api.events.bsky.app/v1', - }, - }, - }, - ) - } - return segmentClient -} - -export const track = async <E extends keyof TrackPropertiesMap>( - event: E, - properties?: TrackPropertiesMap[E], -) => { - await getClient().track(event, properties) -} - -export function useAnalytics() { - const {hasSession} = useSession() - - return React.useMemo(() => { - if (hasSession) { - return { - async screen<E extends keyof ScreenPropertiesMap>( - event: E, - properties?: ScreenPropertiesMap[E], - ) { - await getClient().screen(event, properties) - }, - async track<E extends keyof TrackPropertiesMap>( - event: E, - properties?: TrackPropertiesMap[E], - ) { - await getClient().track(event, properties) - }, - } - } - // dont send analytics pings for anonymous users - return { - screen: async () => {}, - track: async () => {}, - } - }, [hasSession]) -} - -export function init(account: SessionAccount | undefined) { - if (account) { - const client = getClient() - if (account.did) { - const did_hashed = sha256(account.did) - client.identify(did_hashed, {did_hashed}) - Sentry.setUser({id: did_hashed}) - logger.debug('Ping w/hash') - } else { - logger.debug('Ping w/o hash') - client.identify() - } - } -} |