a6a4ceee86
* fixing up typing * better dynamic loader mechanism * buildReqLoaders cleanup * added caching to loaders * ensuring all loaders are async * fe2 plugins error handling fix * feat(shared): true-myth result structures & other auth policy improvements * moving workspaceCore loaders to correct place
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import { LogicError } from '@speckle/ui-components'
|
|
import { fakeMixpanelClient, type MixpanelClient } from '~/lib/common/helpers/mp'
|
|
import { useClientsideMixpanelClientBuilder } from '~/lib/core/clients/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()
|
|
const build = useClientsideMixpanelClientBuilder()
|
|
|
|
let mixpanel: MixpanelClient | undefined = undefined
|
|
|
|
try {
|
|
// Dynamic import to allow suppressing loading errors that happen because of adblock
|
|
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
|
|
}
|
|
}
|
|
}
|
|
})
|