Google analytics with angular app: callback called but no data tracked

see stackoverflow post about google analytics tracking and angular web app ( Tracking Google Analytics pageviews with Angular.js ). I have installed the code below.

This seems to work well, the callback function gets called ... but looking at the GA website, no tracking data is available.

Do you see something 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');
                            }
                        });
                });

      

The code runs during module.run ().

Thanks for the help.

+3


source to share


1 answer


I recommend using this Node Package:

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

Step 1:

Run

install bower 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 for example

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

      

Step 4:

Add this to your config:

AnalyticsProvider
        .setAccount('Your tracking code here')
        .logAllCalls(true)
        .trackPages(true)
        .trackUrlParams(true);

      

0


source







All Articles