Files
speckle-server/packages/frontend-2/plugins/mp.ts
T
Kristaps Fabians Geikins d3ef6788eb feat(fe2): core web vitals report + dynamic raygun tags (#2117)
* feat(fe2): route-based raygun tags

* feat: toggle cwv report

* added ttfb
2024-03-13 11:54:13 +02:00

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