【问题标题】:Google Analytics - Custom iFrame TrackingGoogle Analytics - 自定义 iFrame 跟踪
【发布时间】:2012-10-17 14:33:39
【问题描述】:

我做了一个小小的井字游戏,在http://tic.cwoebker.com 上玩得很好。 实际的井字游戏从 (/tic) 加载并嵌入到 iframe 中。

因此,其他人可以轻松地将游戏嵌入到他们自己的网站上。

我正在 iframe 内进行一些事件跟踪。 现在我已经设置好了,所以它会在两个主页上触发一个页面视图 以及 iframe 中的实际游戏代码。

我想知道如果不是,我是否只能以某种方式触发 iframe 的页面视图 嵌入在http://tic.cwoebker.com 但在另一个站点上。

因此,在根目录 (/) 下跟踪的所有内容都是我网站上的流量,而在 i 框架 (/tic) 中跟踪的所有内容都是通过嵌入另一个网站产生的流量。

现在我在 iframe 中的分析代码如下所示:

 <script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-xxxxxxxxx-x']);
    _gaq.push(['_trackPageview']);

(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>

非常感谢。

【问题讨论】:

    标签: iframe google-analytics


    【解决方案1】:

    由于您位于单独域的 iFrame 中,因此您无法访问父窗口来获取位置。看看这个演示和/或谷歌一下:http://jsfiddle.net/TomFuertes/RRB52/2/

    _gaq.push(['tictactoe._setAccount', 'UA-xxxxxxxxx-x']);
    // Line below causes security issues, thus won't work
    _gaq.push(['_setCustomVar', 1, 'Domain', window.parent.location.host, 3]);
    _gaq.push(['tictactoe._trackPageview']);
    

    您可以在 iFrame 页面上使用查询字符串传递域,您需要将包含代码修改为如下所示:https://stackoverflow.com/a/5697801/94668

    <script type="text/javascript">
    document.write('<iframe src="//tic.cwoebker.com/?url=' + window.location + '"></iframe>');
    </script>
    

    然后你会适当地过滤掉你的谷歌分析。

    【讨论】:

      【解决方案2】:

      您可以使用 Google Analytics(分析)广告系列来跟踪流量。您将需要分发已经具有活动参数的嵌入代码作为嵌入 iframe src 的一部分。

      希望对您有所帮助。

      有兴趣听取其他人的意见。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-07
        • 1970-01-01
        • 1970-01-01
        • 2013-08-17
        相关资源
        最近更新 更多