vue-analytics icon indicating copy to clipboard operation
vue-analytics copied to clipboard

Add information to documentation

Open quimeparle opened this issue 5 years ago • 1 comments

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

quimeparle avatar Dec 11 '19 13:12 quimeparle

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 :)

ScreamZ avatar Dec 11 '19 21:12 ScreamZ