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

46 lines
1.1 KiB

import mixpanel from 'mixpanel-browser'
import { init as amplitudeInit, track as amplitudeTrack } from '@amplitude/analytics-browser'
const mixpanelToken = process.env.MIXPANEL_TOKEN
const amplitudeApiKey = process.env.AMPLITUDE_API_KEY
let initialized = false
export let mixpanelInitialized = false
export let amplitudeInitialized = false
export function init () {
const mixpanelUrl = process.env.MIXPANEL_URL
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, { 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)
}
}