这是我尝试让 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');
}
然后,inclient/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 设置有很多问题