Angulartics GA events not getting tracked

2019-04-21 08:00发布

问题:

I am using angulartics google analytics in my project. I have set it up as the docs say. Its tracking the page views and all in real time but the events is not getting tracked. Here is my code:

view:

// Not getting tracked
<a href="#" ng-click="download()" analytics-on="click" analytics-event="Download">Push</a>

index.html

<!-- Put Your GOOGLE ANALYTICS CODE Below -->
<script src="vendor/angular/angulartics.js"></script>
<script src="vendor/angular/angulartics-ga.js"></script>
<script>
        (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function()
        { (i[r].q=i[r].q||[]).push(arguments)}
        ,i[r].l=1*new Date();a=s.createElement(o),
        m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
        })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
        ga('create', 'XXXXXXXX', 'auto');
        ga('send', 'event', 'button', 'click', 'nav buttons', 4);
    </script>

The download event is not getting tracked. But the same button event below that i have added in the script tag is getting tracked

ga('send', 'event', 'button', 'click', 'nav buttons', 4); // This is being tracked

Event tracking from inside the application logic is also not working when i do like below from inside my controller:

$analytics.eventTrack('Downalod');

I also found this closed issue which one guy had same issue.

Browser Used: Chrome Version 37.0.2062.120 (64-bit)

Is there anything i am missing here? Do i need to enable event tracking or something in the code??

回答1:

I had the same issue. So I was going over the recent commits and found this in the change logs: Google Analytics - do nothing if there is no event category (required) Link

This should fix it:

<a href="#" ng-click="download()" analytics-on="click" analytics-category="Some-Category" analytics-event="Download">Push</a>


回答2:

I've been experiencing the same issue, no events tracked. As @nknj mentioned, and as you can see in the source code:

https://github.com/luisfarzati/angulartics/blob/master/src/angulartics-ga.js#L54-L60

For google analytics you have to provide a category.

I just wanted to add that if you want to use the programmatic version instead of directives you have to pass an object containing the category.

$analytics.eventTrack('eventName', {
    category: 'categoryName'
});


回答3:

I had the same problem (even with analytics-category present) and could solve it through using a newly created tracking snippet from google analytics, which was different than my old one ( I haven't checked which change caused it to work ).



回答4:

You need to remove the last line for google "send".

See documentation here, where it describes:

Make sure you delete any automatic tracking line from your vendor snippet code!

// Google Analytics example
ga('send', 'pageview'); // <---- delete this line!