Chrome中的Google Analytics分析跟踪代码错误

时间:2017-08-24 09:21:09

标签: javascript google-chrome google-analytics

我的谷歌分析跟踪代码看起来像这样(它从他们的网站上复制/粘贴)

<script>
    (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','https://www.google-analytics.com/analytics.js','ga');

    ga('create', 'UA-XXXXXXXXX-X', 'auto');
    ga('send', 'pageview');
</script>

我收到此控制台错误: 未捕获的SyntaxError:意外的标记var(突出显示最后的_gat变量)

    var urchinTracker = function() {},
  _gaq = {
    push: function() {
      try {
        if (arguments[0][0] == '_link') window.location.href = arguments[0][1]
      } catch (er) {}
    }
  },
  _gat = {
    _createTracker: function() {},
    _getTracker: function() {
      return {
        __noSuchMethod__: function() {},
        _link: function(o) {
          if (o) location.href = o;
        },
        _linkByPost: function() {
          return true;
        },
        _getLinkerUrl: function(o) {
          return o;
        },
        _trackEvent: function() {}
      }
    }
  };
cxApi = {
  setCookiePath: function() {},
  chooseVariation: function() {}
}
var _gat = {
  _getTrackerByName: function() {
    _trackEvent: function() {}
  }
};

这似乎只发生在Chrome中?

2 个答案:

答案 0 :(得分:2)

实际上,Ghostery拦截来自Google的analytics.js请求并返回一些过时的javascript,编码为base64(see this comment)似乎是一个问题。如果我卸载Ghostery,这个问题就会消失 - 我仍在运行uBlock Origin,但也不是Ghostery。

答案 1 :(得分:-2)

您需要在第9行将 - (UIViewController *)topViewController { return [self topViewController:[UIApplication sharedApplication].keyWindow.rootViewController]; } - (UIViewController *)topViewController:(UIViewController *)rootViewController { if (rootViewController.presentedViewController == nil) { return rootViewController; } if ([rootViewController.presentedViewController isMemberOfClass:[UINavigationController class]]) { UINavigationController *navigationController = (UINavigationController *)rootViewController.presentedViewController; UIViewController *lastViewController = [[navigationController viewControllers] lastObject]; return [self topViewController:lastViewController]; } UIViewController *presentedViewController = (UIViewController *)rootViewController.presentedViewController; return [self topViewController:presentedViewController]; } 替换为_gat =