manifold/web/lib/service/analytics.ts
mantikoros 38c63fb3ee
Amplitude (#505)
* basic amplitude setup

* delete heap

* track referrers

* basic tracking

* delete unused import

* prettier
2022-06-14 22:00:36 -05:00

34 lines
735 B
TypeScript

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 }
// convenience function
export const withTracking =
(
f: (() => void) | (() => Promise<void>),
eventName: string,
eventProperties?: any
) =>
() =>
Promise.all([f(), track(eventName, eventProperties).promise])
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)
}