miguelzakharia/aurelia-google-analytics

Page Tracking: Option for page title instead of route title

ostyn opened this issue · 8 comments

ostyn commented

First of all, I LOVE this plugin. It's just what I was looking for, well structured, reasonable, clean. Love it.

and now the but...

Problem

I'm currently using a single route to represent multiple unique pages. Think a blog post. Same route. Different content. Different titles. These titles are set using like so

export class BlogPostRoute {
  activate(params, routeConfig, navigationInstruction) {
    //Load blogPost
    routeConfig.navModel.title = blogPost.title;
  }
}

Through the "magic" of the aurelia router, that navModel.title ends up as the title of the page. But it doesn't get pulled into aurelia-google-analytics, which makes me sad.

Proposal

For starters, I will do the work. Second, the gist, I'd like to pass an arg to the the plugin to tell it to grab the title from window.document.title. useDocumentTitle or something like that.

That's all.

Simple. Doesn't break existing behavior. But it give me and others who might need this flexibility an option.

But that's just my first stab at it. What do you think? Can I restructure my code to avoid this in the first place? Let me know what you think!

Hi @ostyn, I'm glad you find the plugin helpful!

I'm not sure this is going to work for your scenario because the page tracking listens to router events in order to grab the information and send it to GA. If I understood your use case, the router is never navigating to another route and therefore will not fire the router:navigation:success event.

Try subscribing to the event in your code and logging to the console to verify. Take a look at line 150 in src/analytics.js for an example. Let me know the result and we can figure out a way forward.

Hmmm... was just gonna file an issue/enhancement and start a pull request for the feature but its similar to this one from @ostyn so I wanted to comment here and maybe we can discuss before we all march off on similar paths. The feature I am interested in is to actually track the route name from the route vs the actual route fragment in google analytics. The reason for this is the following scenario:

I have routes defined that have the user customer number in them like so:

customer/123
customer/222
customer/044
etc...

each route in my app starts this way then they navigate to other other areas via child router. Being that these are dynamic routes they all have a name parameter in the routing config. It would be beneficial to me to see this displayed in analytics as the named route 'i.e. customer-detail' and to see all navs to this route aggregated vs seeing a route for each individual route based on the fragment. Again, in the above scenario ga would show 3 routes to the above customer detail section vs 1 visit for each individual route. With thousands of customers this will get hard to manage and get actual metrics on page views from!

Perhaps an optional config on page-tracking that allows you to set the parameter that is sent to ga with a default to the fragment as it is currently? Thoughts?

I would be willing to contribute to the work if you think this is useful to the community and to others and if you accept contributions!

Thanks again for the plugin @miguelzakharia !

regards,

Kevin

@KevinStong your use case is very similar to @ostyn. Passing a config value to page tracking makes sense and will solve both. I have not used a child router in any of my projects so I don't have any insight as to which value will be sent to GA. I definitely accept and appreciate contributions so please go ahead and give it a shot!

Cool @miguelzakharia I will start working on a branch on this now and will issue the PR when I get it completed!

thanks!

Kev

ostyn commented

Yeah @miguelzakharia, I just checked and router:navigation:success gets fired every time I need it to. So this should work for my case.

And @KevinStrong, that sounds like my issue exactly. Are you suggesting setting a callback/function in the page tracking options for getting the page title? I'm willing to assist however, even if I'm not coding it.

I wasn't going to use the page title @ostyn was going to use the route title attribute so that is available on the router itself - or allow the user the select the way to mark the route... perhaps using title, name, or callback unsure. For this first iteration was thinking keep it simple and go with title. Will have a pull request in before Monday so feel free to hop in on that review and provide feedback and suggestions!

ostyn commented

First attempt at a fix here: #15

2.1.0 was just released with the fix for this issue. Thanks for the contribution!