Summary :
I implemented Angulartics and the angulartics-google-analytics Vendor Plugin in my angular application as per the angulartics
official documentation.
Real time page views
tracked properly but Declarative event tracking
is not getting tracked.
Declarative Event Tracking :
<a href="file.pdf" analytics-on="click" analytics-event="Download" analytics-category="PDF" analytics-label="fileName">Download</a>
Scripts & Tracking Code in index.html :
<!-- GA scripts -->
<script type="text/javascript" src="node_modules/angulartics/dist/angulartics.min.js"></script>
<script type="text/javascript" src="bower_components/angulartics-google-analytics/dist/angulartics-ga.min.js"></script>
<!-- end -->
<!-- Google Analytics Tracking Code -->
<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','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'XX-XXXXXXXX-X', 'auto');
// ga('send', 'pageview');
</script>
<!-- end -->
Agreed :
Data in Google Analytic Reports can take up to 48 hours to process but I was waiting for the events data from past 2 days, still nothing happen.
There are lot of posts on SO with same issue, but didn't get any solution.
Angulartics GA events not getting tracked
Event tracking not working (yet)?
Update :
I get notification in my account related to Missing Tracking Code
.
As I am working on http://localhost
right now.So, this notification is valid. But issue is that real time page views
recorded successfully and declarative events
not getting tracked.
You can always send it manually. This is what I do (In typescript)
$rootScope.$on('$viewContentLoaded', (): void => {
//url tracking
$analytics.pageTrack(location.href);
//event tracking
$analytics.eventTrack('campaign', {
category: 'promotion',
action: 'inquiry',
label: 'awesome'
});
}
You will have to inject $analytics and you may use $location instead of raw url above.
Also, you don't have to wait 48 hours, there is real time events, you can see it right away for last 30 minutes.