Tracking Google Analytics Page Views with AngularJS

前端 未结 21 1003
北恋
北恋 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:23

    Use GA 'set' to ensure routes are picked up for Google realtime analytics. Otherwise subsequent calls to GA will not show in the realtime panel.

    $scope.$on('$routeChangeSuccess', function() {
        $window.ga('set', 'page', $location.url());
        $window.ga('send', 'pageview');
    });
    

    Google strongly advises this approach generally instead of passing a 3rd param in 'send'. https://developers.google.com/analytics/devguides/collection/analyticsjs/single-page-applications

提交回复
热议问题