Angularytics: How to track page views & events on AngularJS's SPA

2,117 views
Skip to first unread message

Gonto

unread,
Jun 3, 2013, 10:52:52 PM6/3/13
to ang...@googlegroups.com
Hey guys,

I've implemented a new service + filter to make it easy to track PageViews and Events with Analytics providers (For now only Google Analytics and Console logger).

I'd love it if you guys could check it out and give me some feedback on what you guys think that should be added/removed.


Thanks for all the help and bests!
Gonto

Arturo Hernandez

unread,
Jul 31, 2013, 10:59:22 AM7/31/13
to ang...@googlegroups.com, gon...@gmail.com
Gonto,

I think you did a great job. I think I am definetly going to be using it. I do have one comment.

<a href="file.pdf" analytics-event="Executable Download">Download</a>

instead of

<a href="file.pdf" analytics-event="Executable Download" analytics-on>Download</a>

Doing so would result in shorter HTML. If my application was simple, I would not worry about it. But, in angular, many applications need to use several tags and it can affect readability. I'm not sure if there is a canonical way of dealing with this sort of issue. I hope others here can weigh in on that.

Martin Gontovnikas

unread,
Jul 31, 2013, 11:02:34 AM7/31/13
to Arturo Hernandez, ang...@googlegroups.com, gon...@gmail.com
Hey,

That's not actually my library. I use filters for logging analytics event :P. https://github.com/mgonto/angularytics#using-the-filter

Bests,

---
Martin Gontovnikas
Software Engineer
Buenos Aires, Argentina

Twitter: @mgonto

Arturo Hernandez

unread,
Jul 31, 2013, 11:21:13 AM7/31/13
to ang...@googlegroups.com, Arturo Hernandez, gon...@gmail.com
That is hilarious!!

In angulartics
<a href="file.pdf" analytics-event="Executable" analytics-category="Downloads" analytics-on>Download</a>

In angularytics
<a href="file.pdf" ng-click="doSomething() | trackEvent:'Downloads':'Executable'">Download</a>

Did you have a particular reason on choosing to implement analytics in a filter instead of a directive? Or is it just open to us to pick on what style do we prefer?

Martin Gontovnikas

unread,
Jul 31, 2013, 11:22:11 AM7/31/13
to Arturo Hernandez, ang...@googlegroups.com, gon...@gmail.com
Because the directive assumes you will actually track events on click.

With filter, you can use any event, like ng-keydown or any custom event from you!

---
Martin Gontovnikas
Software Engineer
Buenos Aires, Argentina

Twitter: @mgonto

Luis Farzati

unread,
Aug 9, 2013, 9:22:33 AM8/9/13
to ang...@googlegroups.com, Arturo Hernandez, gon...@gmail.com
Hey, just to clarify: 

The directive assumes a click event if you don't specify any, e.g.:

<a href="file.pdf" analytics-event="Executable" analytics-category="Downloads" analytics-on>Download</a>

but you can always do

<a href="file.pdf" analytics-event="Executable" analytics-category="Downloads" analytics-on="mouseover">Download</a>
 
or whatever DOM events are allowed :)

It uses angular.bind() internally.
Reply all
Reply to author
Forward
0 new messages