0

I've followed the "tutorial" on Angulartics' website and ended up with this event code on my buttons and links:

Buttons

<button class="btn btn-default" ng-controller="ctrl" ng-click="openModal()" analytics-on="click" analytics-event="button" analytics-categori="Main page" analytics-label="Modal bottom">Open modal!</button>

Links

<a ui-sref="ui.state" data-toggle="collapse" data-target="#navbar" analytics-on="click" analytics-event="button" analytics-categori="Header" analytics-label="FAQ">FAQ</a>

I have injected both angulartics and angulartics.google.analytics to my app and it works as it should, no errors anywhere. I have deleted the ga('send', 'pageview') from the Google Analytics code-snippet.

The event tracking works if I put it in my controller with this snippet:

$analytics.eventTrack('event', {category: 'category', label: 'label'});

Does anyone know what I might be doing wrong when adding the code to my links and buttons?

EDIT

I've tried to remove analytics-on="click" and instead just have analytics-on but that doesn't work either.

<button ng-click="openModal()" analytics-on analytics-event="button" analytics-categori="Main page" analytics-label="Modal bottom">Open modal!</button>
jwanglof
  • 548
  • 1
  • 5
  • 20
  • I wouldn't put ng-controller on the same element you attach an ng-click to... that seems like a bad idea to me I would wrap your button in a node and attach ng-controller to that. – btm1 Jan 27 '15 at 21:51
  • Yeah, that was a bad example.. But I will definitively look into it =) – jwanglof Jan 28 '15 at 06:06

2 Answers2

1

So I figured out what the problem was, I had misspelled "category" in "analytics-category" and therefor Angulartics didn't register any events.

Thanks to btm1 though for getting my thoughts going on other solutions =)

jwanglof
  • 548
  • 1
  • 5
  • 20
0

to answer your question ng-click takes the click handler for that element the same goes for analytics-on="click" the two don't work nicely together because you've got two events conflicting with one another.

The best thing to do would be to create a function in your controller that gets fired via ng-click and then put your google analytics code inside of that function.

btm1
  • 3,866
  • 2
  • 23
  • 26
  • But why doesn't it work on the links? Is it because UI Router transforms ui-sref to a click-event that is fired before analytics-on? – jwanglof Jan 28 '15 at 06:04
  • because ui sref might use mousedown or mouseup or a custom click event all together. – btm1 Jan 28 '15 at 18:04