d3ef6788eb
* feat(fe2): route-based raygun tags * feat: toggle cwv report * added ttfb
37 lines
828 B
TypeScript
37 lines
828 B
TypeScript
/**
|
|
* mixpanel-browser only supports being ran on the client-side (hence the name)! So it's only going to be accessible
|
|
* in client-side execution branches
|
|
*/
|
|
|
|
export default defineNuxtPlugin(async () => {
|
|
const {
|
|
public: { mixpanelApiHost, mixpanelTokenId, logCsrEmitProps }
|
|
} = useRuntimeConfig()
|
|
|
|
const mixpanel = process.client
|
|
? (await import('mixpanel-browser')).default
|
|
: undefined
|
|
if (!mixpanel) {
|
|
return {
|
|
provide: {
|
|
mixpanel: () => {
|
|
throw new Error('Mixpanel is only available on the client-side!')
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Init
|
|
mixpanel.init(mixpanelTokenId, {
|
|
// eslint-disable-next-line camelcase
|
|
api_host: mixpanelApiHost,
|
|
debug: logCsrEmitProps && !!process.dev
|
|
})
|
|
|
|
return {
|
|
provide: {
|
|
mixpanel: () => mixpanel
|
|
}
|
|
}
|
|
})
|