Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass router parameters? #17

Closed
goobdeveloper opened this issue Mar 21, 2017 · 10 comments
Closed

Pass router parameters? #17

goobdeveloper opened this issue Mar 21, 2017 · 10 comments
Assignees

Comments

@goobdeveloper
Copy link

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 calling this.$ua.trackView(constructedScreenName) myself?

@goobdeveloper
Copy link
Author

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.

@ScreamZ
Copy link
Owner

ScreamZ commented Mar 21, 2017

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

@ScreamZ ScreamZ self-assigned this Mar 21, 2017
@ScreamZ
Copy link
Owner

ScreamZ commented Mar 22, 2017

@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

  • Try with true
  • Try with false
  • Try without the attribute and ensure that the name of the route is used.
  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)
  })
`

@ScreamZ ScreamZ added the W.I.P. label Mar 22, 2017
@ScreamZ
Copy link
Owner

ScreamZ commented Apr 16, 2017

@goobdeveloper Poke, you agree with that ?

@goobdeveloper
Copy link
Author

@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.

@cspeer
Copy link
Contributor

cspeer commented Jun 3, 2019

Hey @ScreamZ can we get this merged please? :)

@ScreamZ
Copy link
Owner

ScreamZ commented Jun 3, 2019

@cspeer released under 1.7.0

@ScreamZ ScreamZ closed this as completed Jun 3, 2019
@cspeer
Copy link
Contributor

cspeer commented Jun 3, 2019

Great, thanks! Quick question though: Does this work as a global setting or do I have to pass this along with every route?

@ScreamZ
Copy link
Owner

ScreamZ commented Jun 3, 2019

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

@cspeer
Copy link
Contributor

cspeer commented Jun 3, 2019

yeah, I implemented it on a per route basis now. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants