manifold/functions/src/analytics.ts
Marshall Polaris d00fe7bcd2
Backend robustness to email sending or analytics tracking failures (#728)
* Make `sendEmail` functions await email send success

* Make tracking and email sending not throw on failure
2022-08-15 22:13:38 -07:00

27 lines
654 B
TypeScript

import * as Amplitude from '@amplitude/node'
import { DEV_CONFIG } from '../../common/envs/dev'
import { PROD_CONFIG } from '../../common/envs/prod'
import { isProd, tryOrLogError } from './utils'
const key = isProd() ? PROD_CONFIG.amplitudeApiKey : DEV_CONFIG.amplitudeApiKey
const amp = Amplitude.init(key ?? '')
export const track = async (
userId: string,
eventName: string,
eventProperties?: any,
amplitudeProperties?: Partial<Amplitude.Event>
) => {
return await tryOrLogError(
amp.logEvent({
event_type: eventName,
user_id: userId,
event_properties: eventProperties,
...amplitudeProperties,
})
)
}