Closed goobdeveloper closed 5 years ago
It seems this can be accomplished by changing this line from
Vue.analytics.trackView(to.meta.analytics || to.name)
to
Vue.analytics.trackView(to.meta.analytics || to.path)
Obviously, I suppose some people would want to.name
still, so maybe you could make this some kind of config option? Anyway, I am using a custom router.afterEach
setup to accomplish what I want in the mean time.
Hey! Thanks for the feedback, highly appreciated ;)
I agree with the idea, I'll make something to take that it parameter. I ping you when it's all right.
Best regards
@goobdeveloper
Hey buddy just made a fix, can you try this on your project and tell me if it's okay ? Don't have a testing project under the hand at the moment ? Thanks
Add a meta attribute usePathAnalytics
on the route which take a boolean
vueRouter.afterEach(to => {
// Ignore some routes
if (ignoredViews && ignoredViews.indexOf(to.name.toLowerCase()) !== -1) {
return
}
// If specified : the system will use the path instead of the route name.
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)
})
`
@goobdeveloper Poke, you agree with that ?
@ScreamZ I haven't tried it, but just looking at it, it seems okay to me, so I think you should merge it in. I will update versions and try it that way.
Hey @ScreamZ can we get this merged please? :)
@cspeer released under 1.7.0
Great, thanks! Quick question though: Does this work as a global setting or do I have to pass this along with every route?
As you can see this is passed at every routes for now.
You can submit a PR to this, but I think it's better if you disable router integration and implement the above snippet on your own if you need such functionnality
yeah, I implemented it on a per route basis now. Thanks again!
Hi. Great plugin, thanks for making it. Installation was very easy.
My current issue, though, is that, if I just use the default router integration which passes the route name to GA, none of the route parameters are sent. e.g. visiting
/#/users/1
only sends/users
to GA, instead of/users/1
. Is there a way to make it pass the params, too, other than manually callingthis.$ua.trackView(constructedScreenName)
myself?