Thursday, November 1, 2012

Adding Google Analytics to my angular.js based site

Added code snipped emitted from Google Analytics App to index.html, then added this to main controller
    $scope.$on('$viewContentLoaded', function(event) {
        $window._gaq.push(['_trackPageview', $location.path()]);
    });

Done. Full tracking just works. Amazing!

3 comments:

Anonymous said...
This comment has been removed by a blog administrator.
Marcus K. said...

AngularJS - looks so cool, but currently no project where I could introduce it :-(

LK said...

You can also check out angulartics - http://luisfarzati.github.io/angulartics, a vendor-agnostic module for analytics, currently supporting Google Analytics only, but more providers will be coming in the near future.