2013-12-16 4 views
1

AngularJS 앱에 Google Analytics 코드를 추가하고 싶습니다.AngularJS with Google Analytics

저는 Ruby On Rails를 백엔드 프레임 워크로 사용하고 있습니다. AngularJS application.html.erb Rails 파일은 첫 번째 요청시에만로드됩니다.

그래서 Google Analytics 코드를 viewcontentLoad 이벤트에 넣습니다.

$rootScope.$on('$viewContentLoaded', function() { 

     (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
      (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 
     m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 
     })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 

     ga('create', 'UA-XXXX-Y', 'auto'); 
//  ga('send', 'pageview'); 
     ga('send', 'pageview', {'page': $location.path()}); 
}); 

Google 애널리틱스 코드를 삽입하는 올바른 방법인지는 확실하지 않습니다.

답변