如何使用 Google Analytics 跟踪 IFrame 中的点击次数? [英] How to Track Clicks in an IFrame with Google Analytics?

查看:31
本文介绍了如何使用 Google Analytics 跟踪 IFrame 中的点击次数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我自托管的 Wordpress 网站上的 iframe 内跟踪出站点击.我已经使用 Google Analytics 来跟踪入站访问者(标题中的 GA 代码),但我想知道哪些/有多少访问者点击了我每个页面上 iframe 内的链接.作为记录,iframe 确实来自外部广告商.

I'd like to track outbound clicks within an iframe on my self-hosted Wordpress site. I already use Google Analytics to track inbound visitors (GA code in the header), but I'd like to know which/how many of those visitors click on links within the iframe on each of my pages. For the record, the iframe does come from an external advertiser.

这是我得到的 iframe 代码(使用示例名称代替真实名称):

This is the iframe code I was given (using sample names in place of real ones):

<iframe src="http://www.advertisersite123.com//widget.html?width=510&height=950&product=2" frameborder="0" scrolling="no" width="510" height="950"></iframe>

这行代码目前粘贴在 single.php 上,在页面底部的每个帖子上都会显示一个链接表.

This line of code is currently pasted on single.php, making a table of links appear on every single post at the bottom of the page.

我想知道在此 iframe 中发生了多少次点击(一般点击就可以了,不需要知道它们去了哪里).理想情况下,按我网站上的每个单独网址进行细分,以便我可以确定哪些网址在 iframe 内产生点击的效果更好.

I'd like to know how many clicks (just clicks in general is fine, don't need to know where they go) are occurring in this iframe. Ideally broken down by each individual URL on my website so I can determine which URLs are more successful in generating clicks within the iframe.

如果可能的话,我想创建一个漏斗,告诉我网站的哪些访问者(按来源)通过 iframe 中的点击退出.

And if possible, I'd like to create a funnel that tells me which visitors to my website (by source) exit via clicks in the iframe.

这有可能吗?如果是这样,我应该向页面添加什么代码?

Is any of this possible? And if so, what code do I add to the page?

感谢您的任何帮助,不胜感激!

Thank you for any and all assistance, it is appreciated!

推荐答案

您的要求并不容易做到.一般来说,如果 iframe 页面不是托管在同一个域上,则父页面上不能有 javascript 可以挂钩到 iframe 页面上的事件.尝试访问父页面的 DOM 的 iframe 页面也是如此.这称为跨站点脚本 (XSS),它违反了相同的域源策略.

What you are asking for is not easily done. In general, you cannot have javascript on the parent page that can hook into events on the iframed page if it is not hosted on the same domain. Same thing for the iframe page trying to tap into the parent page's DOM. This is called cross-site scripting (XSS), which goes against the same domain origin policy.

至少,最简单的方法是将 GA 代码放在 iframe 页面上.但这可能不是你能做的事情(尽管询问供应商并没有什么坏处).

At a minimum, the easiest thing to do would be to put the GA code on the iframed page. But that's probably not something you can do (though it couldn't hurt to ask the vendor).

但是一些供应商(通常是 Facebook、Google 和 Twitter 等社交媒体供应商)的小部件会输出带有信息的 iframe.他们会将他们的服务器设置为允许跨域脚本,这将允许您访问 iframe 的 DOM.通常,尽管它们随小部件一起提供 API,可以更轻松地连接到相关事件(如共享事件),因此您不必自己进行(很多)编码.

But some vendors (usually social media vendors such as Facebook, Google and Twitter) will have their widgets that output an iframe w/ info. They will set their server to allow for cross-domain scripting, which would allow you to tap into the iframe's DOM. Usually though they provide an API along with the widget that makes it easier to hook into relevant events (like share events), so that you don't have to do (much) coding yourself.

长话短说,如果没有 iframe 域负责人的参与,您就无法跟踪它.

Basically long story short, there's no way for you to track it without the person in charge of the iframe domain getting involved.

这篇关于如何使用 Google Analytics 跟踪 IFrame 中的点击次数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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