【问题标题】:Google Analytics not working on MeteorJS app谷歌分析不适用于 MeteorJS 应用程序
【发布时间】:2021-03-10 11:31:18
【问题描述】:

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

  1. 已安装 iron-router-ga 库
$ meteor add reywood:iron-router-ga
  1. 根据需要提供 Meteor 设置(在 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');
}

但没有任何效果。在 Google Analytics(分析)仪表板上完全静默。 关于我应该如何调试的任何提示?目标是使用访问的路径/页面跟踪站点访问。

【问题讨论】:

    标签: meteor google-analytics


    【解决方案1】:

    我从来没有使用过你提到的那个包,但是天真的方法效果很好。

    添加到您的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');
    

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

    【讨论】:

      猜你喜欢
      • 2018-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-30
      相关资源
      最近更新 更多