mirror of
https://github.com/luxfi/explorer-v1.git
synced 2026-10-30 19:34:59 +00:00
51 lines
1.2 KiB
JavaScript
51 lines
1.2 KiB
JavaScript
import mixpanel from 'mixpanel-browser'
|
|
import { init as amplitudeInit, track as amplitudeTrack } from '@amplitude/analytics-browser'
|
|
|
|
// @ts-ignore
|
|
const mixpanelToken = process.env.MIXPANEL_TOKEN
|
|
// @ts-ignore
|
|
const amplitudeApiKey = process.env.AMPLITUDE_API_KEY
|
|
let initialized = false
|
|
export let mixpanelInitialized = false
|
|
export let amplitudeInitialized = false
|
|
|
|
export function init () {
|
|
// @ts-ignore
|
|
const mixpanelUrl = process.env.MIXPANEL_URL
|
|
// @ts-ignore
|
|
const amplitudeUrl = process.env.AMPLITUDE_URL
|
|
|
|
if (mixpanelToken) {
|
|
if (mixpanelUrl) {
|
|
mixpanel.init(mixpanelToken, { api_host: mixpanelUrl })
|
|
} else {
|
|
mixpanel.init(mixpanelToken)
|
|
}
|
|
mixpanelInitialized = true
|
|
}
|
|
|
|
if (amplitudeApiKey) {
|
|
if (amplitudeUrl) {
|
|
amplitudeInit(amplitudeApiKey, undefined, { serverUrl: amplitudeUrl })
|
|
} else {
|
|
amplitudeInit(amplitudeApiKey)
|
|
}
|
|
amplitudeInitialized = true
|
|
}
|
|
initialized = true
|
|
}
|
|
|
|
export function trackEvent (eventName, eventProperties = {}) {
|
|
if (!initialized) {
|
|
init()
|
|
}
|
|
|
|
if (mixpanelInitialized) {
|
|
mixpanel.track(eventName, eventProperties)
|
|
}
|
|
|
|
if (amplitudeInitialized) {
|
|
amplitudeTrack(eventName, eventProperties)
|
|
}
|
|
}
|