Add more breadcrumbs (#2141)

zio/stable
Eric Bailey 2023-12-07 18:48:23 -06:00 committed by GitHub
parent 1975f4936a
commit afca4bf701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -2,8 +2,10 @@ import React from 'react'
import {AppState, AppStateStatus} from 'react-native'
import AsyncStorage from '@react-native-async-storage/async-storage'
import {createClient, SegmentClient} from '@segment/analytics-react-native'
import {useSession, SessionAccount} from '#/state/session'
import {sha256} from 'js-sha256'
import {Native} from 'sentry-expo'
import {useSession, SessionAccount} from '#/state/session'
import {TrackEvent, AnalyticsMethods} from './types'
import {logger} from '#/logger'
@ -28,6 +30,7 @@ function getClient(): SegmentClient {
}
export const track: TrackEvent = async (...args) => {
logger.info('analytics: track', {args})
await getClient().track(...args)
}
@ -37,9 +40,11 @@ export function useAnalytics(): AnalyticsMethods {
if (hasSession) {
return {
async screen(...args) {
logger.info('analytics: screen', {args})
await getClient().screen(...args)
},
async track(...args) {
logger.info('analytics: track', {args})
await getClient().track(...args)
},
}
@ -60,6 +65,7 @@ export function init(account: SessionAccount | undefined) {
if (account.did) {
const did_hashed = sha256(account.did)
client.identify(did_hashed, {did_hashed})
Native.setUser({id: did_hashed})
logger.debug('Ping w/hash')
} else {
logger.debug('Ping w/o hash')

View File

@ -1,8 +1,9 @@
import React from 'react'
import {createClient} from '@segment/analytics-react'
import {sha256} from 'js-sha256'
import {TrackEvent, AnalyticsMethods} from './types'
import {Browser} from 'sentry-expo'
import {TrackEvent, AnalyticsMethods} from './types'
import {useSession, SessionAccount} from '#/state/session'
import {logger} from '#/logger'
@ -29,6 +30,7 @@ function getClient(): SegmentClient {
}
export const track: TrackEvent = async (...args) => {
logger.info('analytics: track', {args})
await getClient().track(...args)
}
@ -38,9 +40,11 @@ export function useAnalytics(): AnalyticsMethods {
if (hasSession) {
return {
async screen(...args) {
logger.info('analytics: screen', {args})
await getClient().screen(...args)
},
async track(...args) {
logger.info('analytics: track', {args})
await getClient().track(...args)
},
}
@ -59,6 +63,7 @@ export function init(account: SessionAccount | undefined) {
if (account.did) {
const did_hashed = sha256(account.did)
client.identify(did_hashed, {did_hashed})
Browser.setUser({id: did_hashed})
logger.debug('Ping w/hash')
} else {
logger.debug('Ping w/o hash')