Files
speckle-server/packages/frontend-2/plugins/mp.ts
T
Kristaps Fabians Geikins b02a07e2b6 feat: Frontend 2.0 MVP
2023-05-08 10:47:01 +03:00

37 lines
810 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
})
return {
provide: {
mixpanel: () => mixpanel
}
}
})