angular-google-analytics缺少跟踪代码

时间:2016-07-27 14:23:33

标签: angularjs google-analytics

我正在使用'angular-google-analytics'(https://github.com/revolunet/angular-google-analytics)。

下面你可以找到我用过的配置。

我正在收到Google Analytics通知 - “缺少跟踪代码”。可能我做错了什么......

有人可以建议,可能出现什么问题?

angular.module('myModule', ['angular-google-analytics']);

.....
// The configuration is as below 
AnalyticsProvider.logAllCalls(true).startOffline(true).useECommerce(true, true);
        AnalyticsProvider.setAccount('UA-XXXXXXX-1');
        AnalyticsProvider.setDomainName('mywebsite.net');      AnalyticsProvider.setHybridMobileSupport(true);

.....

// in Controllers, Analytics is injected as below
function UserItemsController($scope, $rootScope,  Analytics) {
    ....

    Analytics.trackPage('/user/' + $scope.currentUserName);
    Analytics.pageView();
}

2 个答案:

答案 0 :(得分:1)

此问题已得到解决。我想在这里分享解决方案,也许有人会发现它很有用。

要解决此问题,我已将下一个脚本(由谷歌提供)添加到我的代码中。请注意,“角度 - 谷歌分析”的文档中没有提及它添加代码是必须的,而且可能非常令人困惑。



<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','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-xxxxxxxxx-1', 'auto');
  ga('send', 'pageview');

</script>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

是的,您需要为您的网站/应用添加Google Analytics代码。

为此,请访问以下链接:

https://support.google.com/analytics/answer/1008080?hl=en

希望它对你有所帮助。

干杯!

相关问题