Tracking Google Analytics Page Views with AngularJS

前端 未结 21 948
北恋
北恋 2020-11-27 09:14

I\'m setting up a new app using AngularJS as the frontend. Everything on the client side is done with HTML5 pushstate and I\'d like to be able to track my page views in Goog

21条回答
  •  再見小時候
    2020-11-27 09:26

    If you're using ui-router you can subscribe to the $stateChangeSuccess event like this:

    $rootScope.$on('$stateChangeSuccess', function (event) {
        $window.ga('send', 'pageview', $location.path());
    });
    

    For a complete working example see this blog post

提交回复
热议问题