vue-analytics
vue-analytics copied to clipboard
Add information to documentation
By default the views tracker sends the name of the route when it is integrated with vue-router. The doc mentions the possibility of customizing the name of the view but not how to indicate the path of the route. Based on your code I used the usePathAnalytics parameter to fix this problem. It's the best pratice ? thanks for your help
Hello,
You have two options:
- Adding a meta:
{analytics: "someValue"}
to your route config. - use
usePathAnalytics
to use route name.
// If specified : the system will use the path instead of the route name.
Vue.analytics.trackView(to.meta.analytics || to.name, trackPage)
const viewName = to.meta.usePathAnalytics ? to.path : to.name
// Dispatch vue event using meta analytics value if defined otherwise fallback to route name/path.
Vue.analytics.trackView(to.meta.analytics || viewName, trackPage)
Here is the internal code matching that :)