dongqiao6730 2013-07-16 17:36
浏览 30
已采纳

如何在iFrame中使用Google Analytics进行访问者推介?

Please let me know if this should go on serverfault.. I'd like to know if it is possible to get a visitor referral, to know where he/she comes from from within an iFrame. The trouble I have is if someone say clicks a link on twitter (or any other site) that goes to a given page - the referral Google Analytics captures within the iframe is that of the parent window and not the referral itself.

what's the trick ? Thanks !

  • 写回答

1条回答 默认 最新

  • dqhr76378 2013-07-16 17:41
    关注

    It is clearly documented in their help center:

    Installing the Analytics tracking code on a site that uses frames requires some careful consideration to ensure that your traffic is tracked accurately, and that the referral information is retained.

    We recommend that a site using frames includes the tracking code in the section of the frameset (parent) page, as well as directly before the tag of each child frame that you want to track. If you place your tracking code within a tag thinking that this is equivalent to the body, the code will not run and no data will be recorded.

    If all frames on the site reside on the same domain, then referral information can be properly recorded as long as you've installed the tracking code on the first page users visit on the site.


    The Solution:

    • Load the iframe using _getLinkerUrl to link the visit inside the iframe with the visit on the top frame
    • Use P3P headers on the iframed page to work around stupid internet explorer.

    Additional Notes:

    • Even if you don't care about the top level page you should add a tag into it, if you don't you can't use _getLinkerUrl and you lose the traffic source, etc. If you don't use _getLinkerUrl GA inside the iframe will think it's a brand new visit referral from the top level page.
    • Setting cookies inside an iframe, in a third-party domain is the definition of a third-party cookie. Because of that any browser that is set to block third-party cookies will block the GA cookies and GA won't work. This include Safari (both Desktop and Mobile) that are set to block third-party cookies by default. So if visits using Safari or iDevices are important for you (likely these days) this tracking won't probably give you good results. The only solution is to eliminate the iframed page, either put it in your domain or open it in a new window/tab.

    Source: #11724605

    Hope this helps!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题