-
-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Description
I've noticed that umTrackView is triggered twice when a page uses multiple <NuxtPage> components, e.g. when there is a parent route or template with a <NuxtPage /> and a child route that also renders <NuxtPage />.
See nested routes in the Nuxt docs for details: https://nuxt.com/docs/4.x/guide/directory-structure/app/pages#nested-routes
Steps to Reproduce
- Enable
autoTrackinnuxt-umami. - Create multiple nested pages with
<NuxtPage />inside its template. - Navigate to a child route so that both the parent and child
<NuxtPage>are rendered. - Observe that
umTrackViewis called twice for a single navigation.
Expected Behavior
umTrackView should be triggered only once per completed navigation, regardless of how many <NuxtPage> components exist on the page.
Actual Behavior
When there are multiple <NuxtPage> components, umTrackView is fired twice because the page:finish hook is triggered for every ` component.
Why This Matters
This leads to duplicate view events being sent to Umami, which skews analytics data.
Possible Solution
I'm not really sure how to solve this reliably, but here are some ideas:
- Track the last
route.fullPathand avoid duplicateumTrackViewcalls whenpage:finishfires multiple times for the same route. - Debounce
page:finishcalls so that only the last one is used for tracking. - Find another hook that only fires once per navigation, e.g. via Vue Router. Note that
afterEachwill fire before the new page title is set...
Thanks for maintaining this package! π