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!

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

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程