【发布时间】:2018-01-05 22:54:20
【问题描述】:
我正在尝试为我的 angularjs 网站设置新的谷歌分析标签。
我基本上把这个添加到我的index.html:
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=GOOGLE-ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'GOOGLE-ID'); //remove in order to avoid sending hits on index twice
</script>
这是我的 script.js:
var app = angular.module('app', ['plangular','ngRoute', 'ngSanitize', 'slick', 'chart.js', 'ngMeta']);
我补充说:
app.run(['ngMeta', '$rootScope' , '$location', '$window', function(ngMeta,$rootScope , $location, $window) {
ngMeta.init();
$window.gtag('create', 'GOOGLE-ID', 'auto');
$rootScope.$on('$stateChangeSuccess', function (event) {
$window.gtag('send', 'pageview', $location.path());
});
}]);
但我在分析页面上看不到任何点击,除了索引。
【问题讨论】:
标签: angularjs google-analytics