Files
speckle-server/packages/frontend-2/plugins/007-mpClient.client.ts
T
Kristaps Fabians Geikins ee5ae8af62 fix(fe2): accept invite before onboarding after sign up (#2491)
* explicitly ordering global middlewares

* various subscription fixes & WIP project invite middleware

* SSR invite accept & toast notifs seem to work

* backend support for mixpanel

* mixpanel be logic -> shared

* minor fix

* finissh

* lint fix

* minor comment adjustments

* better adblock handling
2024-07-11 11:45:11 +03:00

38 lines
1.0 KiB
TypeScript

import { LogicError } from '@speckle/ui-components'
import { fakeMixpanelClient, type MixpanelClient } from '~/lib/common/helpers/mp'
/**
* 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 logger = useLogger()
let mixpanel: MixpanelClient | undefined = undefined
try {
// Dynamic import to allow suppressing loading errors that happen because of adblock
const builder = (await import('~/lib/core/clients/mp'))
.useClientsideMixpanelClientBuilder
const build = builder()
mixpanel = (await build()) || undefined
} catch (e) {
logger.warn(e, 'Failed to load mixpanel in CSR')
}
if (!mixpanel) {
// Implement mocked version
mixpanel = fakeMixpanelClient()
}
return {
provide: {
mixpanel: () => {
if (!mixpanel) throw new LogicError('Mixpanel unexpectedly not defined')
return mixpanel
}
}
}
})