【问题标题】:Prevent Duplication of ga.js for Google Analytics (GA) and Google Website Optimizer (GWO)防止 Google Analytics (GA) 和 Google 网站优化器 (GWO) 的 ga.js 重复
【发布时间】:2012-04-12 17:37:36
【问题描述】:

看起来 Google Analytics 代码与 Google 网站优化器 (GWO)* 相同;两者都来自http://www.google-analytics.com/ga.js。但是,在 GA 和 GWO 管理面板上,Google 要求我们包含(即复制粘贴)其各自的跟踪代码,这些代码都包含对 ga.js 的相同引用。也许只是为了指令简单?因此,当多个页面想要同时启用 GA 跟踪和 A/B 测试时,我看到多个页面有对 ga.js 的冗余引用。

我的问题是我们可以执行以下操作吗?希望这对那些不熟悉 JavaScript 但需要配置 GA 和 GWO 的人有用。

<head>
<script>
var _gaq = _gaq || [];
_gaq.push(['gwo._setAccount', 'UA-xxxxxxx-x']);
_gaq.push(['gwo._trackPageview', '/yyyyyyyyyy/test']);
</script>
<!-- All other meta tags. -->

<!-- Let this script serves both for the regular GA tracking and GWO A/B test. -->
<script>
(function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
</head>

*GWO 脚本通常用于 A/B 测试。

【问题讨论】:

  • 为什么不测试一下看看会发生什么?

标签: javascript google-analytics google-website-optimizer


【解决方案1】:

是的,您可以包含一次函数 snipet,但您缺少配置的 GA 部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多