【发布时间】:2015-02-03 03:53:42
【问题描述】:
这是我尝试让 Google Analytics 与 Iron Router 一起使用
在lib/analytics.js 我有以下代码(从分析中的代码页粘贴):
if (Meteor.isClient) {
(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-45905917-2', 'ec2-54-246-15-224.eu-west-1.compute.amazonaws.com');
}
那么,client/router.coffee 中的代码如下:
Router.configure layoutTemplate: 'layout'
Router.map ->
@route 'home',
path: '/'
template: 'home'
after: -> ga('send', 'pageview')
for link in Pages.links
route =
path: link.url
template: link.toTemplate
after: -> ga('send', 'pageview')
@route link.toTemplate, route
但这似乎没有奏效。我该如何解决?
编辑添加:
我尝试过 GAnalytics,但我的部署设置和 Meteor 设置存在很多问题
【问题讨论】:
-
您好,这是一种解决方法,所以我不会将此作为答案发布,但我最近通过在我的
html模板中的<script></script>标记中粘贴 Google Analyics 代码使其工作。像这样:view-source:mixtape.meteor.com -
看看这篇文章:bicobic.com/posts/BkFDo4CqcSnGcGtri 这通过脚本加载器加载 GA-Script,这不是必需的,但它显示了将脚本包含在模板中的方法。在你的布局中调用它。检查 Chrome 的 Google Analytics Debugger。
标签: javascript google-analytics coffeescript meteor iron-router