2

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)?

Event tracking not working

Update :

I get notification in my account related to Missing Tracking Code.

enter image description here

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.

Community
  • 1
  • 1
Debug Diva
  • 26,058
  • 13
  • 70
  • 123
  • 1
    I see no issue with your code. But may be these points might help you debug - 1. There is no ng-click on the anchor tag. This shouldn't be affecting it but just test, 2. Try testing on different browsers, sometimes there might be a bug with browser version, 3. Check if there are any console errors. 4. Check if all the required attributes have been used, go check the google analytics documentation if some attributes have changed. In my case there was the analytics-category attribute that was missing , that is why the event was not getting triggered to Google analytics. – VishwaKumar Aug 25 '16 at 09:25
  • 1
    @VishwaKumar, thanks for the suggestions i will cross check these soon and let you know. – Debug Diva Aug 26 '16 at 05:10

1 Answers1

1

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.

YOU
  • 120,166
  • 34
  • 186
  • 219
  • I totally agree with you , but as per the documentation `declarative event tracking` also working if we want to know the clicks or downloads on particular button or link. – Debug Diva Aug 22 '16 at 05:30
  • @RohitJindal, the sample in document do works with angular 1.1.5 too, but not later for me. – YOU Aug 22 '16 at 06:15
  • But it was not written anywhere in the `document`(https://angulartics.github.io/) that it will not work with later versions of angular 1.1.5. – Debug Diva Aug 22 '16 at 06:34
  • Still i am waiting for the answer. I tried to debug not able to find the issue. – Debug Diva Aug 22 '16 at 07:07
  • what is your expected angular version btw? – YOU Aug 22 '16 at 07:15
  • I am using `1.4.7` – Debug Diva Aug 22 '16 at 07:48
  • with minor adjustment to sample provided by angulartics, It is working under 1.4.7, with ng-route. - https://rawgit.com/S-YOU/d91a08ca374111d0b13bd384c1b9b964/raw/ba6024db6ffa54dd87bbb13e00fdd8fa1c7e7dcb/angulartics.html#/, but I think there is some issues with dynamic sites, which I end up manually triggering it. – YOU Aug 22 '16 at 07:56
  • I'm getting event tracking on a default install. What version of angulartics and angulartics-google-analytics are you on? Have you changed any of the config options? Any chance you can reproduce the code on Plunker etc? – timelfelt Aug 22 '16 at 23:44
  • @timelf123 angular-google-analytics - `v0.2.1` and angulartics - `v1.1.2`. As GA is working with whole application so can not upload the code on plunker.I descibe everything in the question with code snippet. – Debug Diva Aug 23 '16 at 08:29
  • PS I'm an angulartics contrib and I'm using the same version mix and having no issues even on my localhost, so it seems to be env dependent. I know it's hard to separate your app logic but without seeing a plunker I can't really help you http://i.imgur.com/kjqcO6C.png Also make sure you have a category prop filled in, as GA requires this for events – timelfelt Aug 23 '16 at 14:10
  • is there a chance that a tag is dynamically inserted and angular is not $compiled or there is other click handlers, that does not bubble – YOU Aug 24 '16 at 02:52
  • @timelf123 i successfully filled the category prop but issue remain same. – Debug Diva Aug 24 '16 at 07:08
  • @YOU, i am using static tags – Debug Diva Aug 24 '16 at 07:09
  • sorry to ask you awkward question, but thats not something blocked by pop up blocker right? – YOU Aug 24 '16 at 10:40