Google Analytics(分析)&的iFrame [英] Google Analytics & iFrame

查看:135
本文介绍了Google Analytics(分析)&的iFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个简单的页面,当用户点击链接时,iframe会打开。我试图使用

http://www.google.com/support/analytics/bin/answer.py?hl=zh_CN&answer=55527

  pageTracker._trackPageview('/ outgoing / example.com'); 

在iframe中 - 但它似乎不工作?我已阅读此页



code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html#trackingIFrames

似乎我使用iframe.src = pageTracker._getLinkerUrl将一些cookie信息传递给iframe - 问题是我想跟踪iframe内的东西(即事件等),而我得到一个pageTracker is undefined的错误。



我需要包含类似于

 < script type =text / javascript> 
var gaJsHost =((https:== document.location.protocol)?https:// ssl。:http:// www。);
document.write(unescape(%3Cscript src ='+ gaJsHost +google-analytics.com/ga.js'type ='text / javascript'%3E%3C / script%3E));
< / script>

- 让页面跟踪工作。我认为Publisher UA-XXXXX-XID将通过cookies传递,一切都会正常工作吗?

任何想法

解决方案

是的,您必须在您的框架页面中包含GA样板代码

 < script type =text / javascript> 
var gaJsHost =((https:== document.location.protocol)?https:// ssl。:http:// www。);
document.write(unescape(%3Cscript src ='+ gaJsHost +google-analytics.com/ga.js'type ='text / javascript'%3E%3C / script%3E));
< / script>

浏览器将每一个框架都视为一个单独的窗口,并带有单独的dom和javascript环境,能够在框架页面中访问pageTracker,您必须在此页面中包含ga.js脚本。



请注意,您还需要添加

 < script type =text / javascript> 
尝试{
var pageTracker = _gat._getTracker(UA-XXXXXX-X);
} catch(err){}
< / script>

这样pageTracker对象就被实际定义了。
最后,请注意,框架页面和框架页面上的两个pageTracker JavaScript对象(虽然它们具有相同的标识符)是不同的JS对象。这是由于JS将每个帧保存在它自己的窗口对象中的结果,这实际上意味着一个JS范围。


So I have a simple page and when a user clicks on a link an iframe opens. I am trying to use the

http://www.google.com/support/analytics/bin/answer.py?hl=en&answer=55527

pageTracker._trackPageview('/outgoing/example.com');

Inside the iframe - but it seems that its not working ? I have read this page

code.google.com/apis/analytics/docs/tracking/gaTrackingSite.html#trackingIFrames

And it seems that I use the "iframe.src = pageTracker._getLinkerUrl" to pass some cookie info to the iframe - the problem is that I want to track stuff INSIDE the iframe (i.e. such as events etc) and I get a "pageTracker is undefined" error.

Do I need to include something like

<script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
    </script>

inside the iFrame - to get the pageTracker to work. I take it that the "Publisher UA-XXXXX-X" ID will be passed via cookies and everything will work?

Any ideas

解决方案

Yes, you have to include the GA boilerplate code inside your framed page

<script type="text/javascript">
    var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
    document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>

Browsers regard each and every frame as a separate window with its separate dom and javascript environment, so to be able to access pageTracker in the framed page you must include the ga.js script in this page as well.

Note that you'll also need to add

<script type="text/javascript"> 
 try {
  var pageTracker = _gat._getTracker("UA-XXXXXX-X");
 } catch(err) {}
</script>

So that the pageTracker object is actually defined. Finally, please also note that the two pageTracker javascript objects on both the framed page and the framing page, although they have the same identifier are different JS objects. That's a result of the fact that JS keeps each frame in its own window object, which practically means a JS scope.

这篇关于Google Analytics(分析)&amp;的iFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆