Improve type checking for metrics events (#2632)
This commit is contained in:
parent
bc502edae1
commit
157404132f
3 changed files with 42 additions and 37 deletions
|
@ -6,7 +6,7 @@ import {sha256} from 'js-sha256'
|
|||
import {Native} from 'sentry-expo'
|
||||
|
||||
import {useSession, SessionAccount} from '#/state/session'
|
||||
import {TrackEvent, AnalyticsMethods} from './types'
|
||||
import {ScreenPropertiesMap, TrackPropertiesMap} from './types'
|
||||
import {logger} from '#/logger'
|
||||
|
||||
type AppInfo = {
|
||||
|
@ -29,20 +29,30 @@ function getClient(): SegmentClient {
|
|||
return segmentClient
|
||||
}
|
||||
|
||||
export const track: TrackEvent = async (...args) => {
|
||||
await getClient().track(...args)
|
||||
export const track = async <E extends keyof TrackPropertiesMap>(
|
||||
event: E,
|
||||
properties?: TrackPropertiesMap[E],
|
||||
) => {
|
||||
await getClient().track(event, properties)
|
||||
}
|
||||
|
||||
export function useAnalytics(): AnalyticsMethods {
|
||||
export function useAnalytics() {
|
||||
const {hasSession} = useSession()
|
||||
|
||||
return React.useMemo(() => {
|
||||
if (hasSession) {
|
||||
return {
|
||||
async screen(...args) {
|
||||
await getClient().screen(...args)
|
||||
async screen<E extends keyof ScreenPropertiesMap>(
|
||||
event: E,
|
||||
properties?: ScreenPropertiesMap[E],
|
||||
) {
|
||||
await getClient().screen(event, properties)
|
||||
},
|
||||
async track(...args) {
|
||||
await getClient().track(...args)
|
||||
async track<E extends keyof TrackPropertiesMap>(
|
||||
event: E,
|
||||
properties?: TrackPropertiesMap[E],
|
||||
) {
|
||||
await getClient().track(event, properties)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue