Files
speckle-server/packages/frontend-2/plugins/008-mp.client.ts
T
Kristaps Fabians Geikins 4da196ec48 feat(fe2): proper utm collection + idempotent Route Visited tracking (#2497)
* fix(fe2): utm not being tracked like it was in fe1

* fix(fe2): idempotent mp Route Visited calls
2024-07-11 14:52:41 +03:00

31 lines
734 B
TypeScript

import { useMixpanel } from '~/lib/core/composables/mp'
import type { RouteLocationNormalized } from 'vue-router'
import type { Optional } from '@speckle/shared'
export default defineNuxtPlugin(() => {
const mp = useMixpanel()
const router = useRouter()
const route = useRoute()
let previousPath: Optional<string> = undefined
const track = (to: RouteLocationNormalized) => {
const path = to.path
if (path === previousPath) return
const pathDefinition = getRouteDefinition(to)
mp.track('Route Visited', {
path,
pathDefinition
})
previousPath = path
}
// Track init page view
track(route)
// Track page view after navigations
router.afterEach((to) => {
track(to)
})
})