Blockchain explorer for Ethereum based network and a tool for inspecting and analyzing EVM based blockchains.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
blockscout/apps/block_scout_web/assets/js/lib/analytics.js

51 lines
1.2 KiB

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)
}
}