Files
speckle-server/packages/frontend-2/plugins/mp.ts
T
Kristaps Fabians Geikins 53b62076d0 feat: extra mp properties to troubleshoot odd events [WBX-294] (#2068)
* fix(fe2): remove mp Sign Up track, rely on the server to do this

* adding server version
2024-02-21 19:13:00 +02:00

38 lines
836 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 }
} = 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
// TODO: Separate token for new frontend?
mixpanel.init(mixpanelTokenId, {
// eslint-disable-next-line camelcase
api_host: mixpanelApiHost,
debug: !!process.dev
})
return {
provide: {
mixpanel: () => mixpanel
}
}
})