1

我已經在我的Angular單頁面應用程序中進行了一段時間的GA設置。在主要的index.html的底部我有GA跟蹤代碼:Angular SPA中的Google Analytics(分析)

<script> 
    (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-56056824-2", "auto"); 
    ga("send", "pageview"); 
</script> 

然後,以確保新的瀏覽量每用戶進入一個新的視圖時被炒到谷歌,我添加了一個監聽器爲viewContentLoaded然後向GA發佈新的綜合瀏覽量。

app.run(["$rootScope", "$location", "$window", function($rootScope, $location, $window){ 
    $rootScope.$on("$viewContentLoaded", function(event){ 
    $window.ga("send", "pageview", { page: $location.url() }); 
    }); 
}]); 

這一切都很好,但我注意到跳出率極低(3%)。我現在已經意識到發生了什麼。用戶進入主頁並啓動GA腳本,發送主頁的綜合瀏覽量。然後,一旦JavaScript執行和視圖加載,第二個瀏覽量使用上面的JavaScript發送。

這顯然會導致不正確的瀏覽量結果和跳出率。我如何正確設置?

+0

我可以建議使用Angulartics https://luisfarzati.github.io/angulartics/ –

回答

0

從腳本中刪除此行:

ga("send", "pageview"); 
+0

基於最新的[谷歌分析(https://開頭開發商。 google.com/analytics/devguides/collection/analyticsjs/single-page-applications)文檔我建議設置'ga('set','page','$ location.url()')' –

相關問題