2022-06-15 03:00:36 +00:00
|
|
|
import {
|
|
|
|
init,
|
|
|
|
track,
|
|
|
|
identify,
|
|
|
|
setUserId,
|
|
|
|
Identify,
|
|
|
|
} from '@amplitude/analytics-browser'
|
|
|
|
|
|
|
|
import { ENV_CONFIG } from 'common/envs/constants'
|
|
|
|
|
|
|
|
init(ENV_CONFIG.amplitudeApiKey ?? '', undefined, { includeReferrer: true })
|
|
|
|
|
|
|
|
export { track }
|
|
|
|
|
2022-06-15 21:34:34 +00:00
|
|
|
// Convenience functions:
|
|
|
|
|
|
|
|
export const trackCallback =
|
|
|
|
(eventName: string, eventProperties?: any) => () => {
|
|
|
|
track(eventName, eventProperties)
|
|
|
|
}
|
|
|
|
|
2022-06-15 03:00:36 +00:00
|
|
|
export const withTracking =
|
|
|
|
(
|
|
|
|
f: (() => void) | (() => Promise<void>),
|
|
|
|
eventName: string,
|
|
|
|
eventProperties?: any
|
|
|
|
) =>
|
2022-06-15 21:34:34 +00:00
|
|
|
async () => {
|
|
|
|
const promise = f()
|
|
|
|
track(eventName, eventProperties)
|
|
|
|
await promise
|
|
|
|
}
|
2022-06-15 03:00:36 +00:00
|
|
|
|
|
|
|
export async function identifyUser(userId: string) {
|
|
|
|
setUserId(userId)
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function setUserProperty(property: string, value: string) {
|
|
|
|
const identifyObj = new Identify()
|
|
|
|
identifyObj.set(property, value)
|
|
|
|
await identify(identifyObj)
|
2022-06-14 16:54:58 +00:00
|
|
|
}
|