Search code examples
javascriptangularjsgoogle-analyticsangulartics

Angulartics doesn't track my events on buttons or links


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>

Solution

  • 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 =)