谷歌分析不工作在MeteorJS应用程序



我正在按照https://github.com/reywood/meteor-iron-router-ga上的说明在MeteorJS web应用程序上实现Google Analytics。

  1. 已安装的铁路由器-ga库
$ meteor add reywood:iron-router-ga
  1. 根据需要提供流星设置(在Heroku环境变量上):
{
"public": {
"ga": {
"id": "UA-XXXX-Y"
}
}
}
  1. 找到route.js,添加以下代码:
Router.configure({
trackPageView: true, //https://github.com/reywood/meteor-iron-router-ga
...
});
if (Meteor.isClient) {
Router.plugin('reywood:iron-router-ga');
}

但是没有任何效果。在谷歌分析仪表板上完全沉默。有什么提示我应该如何调试这个吗?目标是通过访问的路径/页面跟踪站点访问。

我从未使用过您提到的那个包,但是这种朴素的方法工作得很好。

添加到您的index.html的头部:

<script type="text/javascript" src="/js/google_analytics.js"></script>

Inpublic/js/google_analytics.js:

(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-xxxxxxxx-y', 'auto');
ga('require', 'displayfeatures');
ga('send', 'pageview');

一个问题可能是,当这些页面通过客户端路由到达时,它是否仍然跟踪页面浏览量,我认为答案是肯定的,但尚未验证。

最新更新