meteor - 谷歌分析不适用于 MeteorJS 应用程序
问题描述
我正在按照https://github.com/reywood/meteor-iron-router-ga上的说明在MeteorJS 网络应用程序上实施 Google Analytics。
- 安装了 iron-router-ga 库
$ meteor add reywood:iron-router-ga
- 根据需要提供 Meteor 设置(在 Heroku 环境变量上):
{
"public": {
"ga": {
"id": "UA-XXXX-Y"
}
}
}
- 找到route.js,添加如下代码:
Router.configure({
trackPageView: true, //https://github.com/reywood/meteor-iron-router-ga
...
});
if (Meteor.isClient) {
Router.plugin('reywood:iron-router-ga');
}
但没有任何效果。在 Google Analytics(分析)仪表板上完全静默。关于我应该如何调试的任何提示?目标是使用访问的路径/页面跟踪站点访问。
解决方案
我从来没有使用过你提到的那个包,但天真的方法效果很好。
添加到您的头部index.html
:
<script type="text/javascript" src="/js/google_analytics.js"></script>
在public/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');
一个问题可能是,当通过客户端路由到达这些页面时,这是否仍会跟踪页面浏览量,我认为答案是肯定的,但尚未验证。
推荐阅读
- swift - 显示没有 UIImage 的 base64 编码图像
- matlab - 如何在 plot3 中使用渐进式着色?
- entity-framework-core - 1 对多,以复合键为主键
- node.js - 如何确定与本地服务器日期和数据库日期的时区偏移
- java - InputStream xls文件无法解码
- javascript - 饼图的每个部分在chartsjs中随机颜色
- c++ - 对(我认为是)不可复制元素的列表进行分区
- c# - 将 XDocument.Descendants 与合并运算符一起使用??和可为空的类型
- python - 有效地添加两个不同大小的一维数组
- java - BlueCove 无法连接做设备“权限被拒绝 [13]”