Tracking Google Analytics Page Views with AngularJS

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

    I found the gtag() function worked, instead of the ga() function.

    In the index.html file, within the section:

    
    
    

    In the AngularJS code:

    app.run(function ($rootScope, $location) {
      $rootScope.$on('$routeChangeSuccess', function() {
        gtag('config', 'TrackingId', {'page_path': $location.path()});
      });
    });
    

    Replace TrackingId with your own Tracking Id.

提交回复
热议问题