3

looking to stackoverflow post about tracking by google analytics an angular web app (Tracking Google Analytics Page Views with Angular.js) I put in place the code below.

It seems to work well, the callback function gets invoked... but looking to GA web site no tracking data are available.

Do you see anything wrong with this code?

/*tracking in localhost*/
                window.ga('create', 'MY_WEB_SITE_ID_HERE', {
                    cookieDomain: 'none'
                 });

                //to every route change, requests a track to google
                $rootScope.$on('$routeChangeSuccess', function(e, current, pre) {
                    window.ga('send', 'pageview',
                        {
                            page: $location.path(),
                            hitCallback: function() {
                                alert('analytics.js done sending data');
                            }
                        });
                });

Code runs during module.run().

Thanks a-lot for help.

Community
  • 1
  • 1
imkeva
  • 31
  • 1

1 Answers1

0

I recommend using this Node Package:

https://www.npmjs.com/package/angular-google-analytics

Step 1:

Run

bower install angular-google-analytics

Step 2:

Add this script tag:

<script src="/bower_components/angular-google-analytics/dist/angular-google-analytics.js"></script>

Step 3: Add angular-google-analytics to your app.main e.g.

app.run(function(Analytics) {});

Step 4:

Add this to your config:

AnalyticsProvider
        .setAccount('Your tracking code here')
        .logAllCalls(true)
        .trackPages(true)
        .trackUrlParams(true);
webdev5
  • 467
  • 1
  • 8
  • 22