0
我有一个网页应用程序,它是一个带有iframe的单个页面。 Page和iframe来自同一个来源。我试图在iframe中发送一个事件从Google Analytics这样的:从iframe内发送Google Analytics事件?
if(typeof parent.ga !== 'undefined') parent.ga('send','event', Category, Action, Label);
我也尝试过这种做法:
if(typeof parent.ga !== 'undefined') parent.sendGaEvent(Category, Action, Label);
而且在父功能如下:
function sendGaEvent(Category, Action, Label){
ga('send','event', Category, Action, Label);
}
这些方法似乎都不起作用。这些事件不会在Google Analytics中显示。但是,如果我从iframe的父级发送类似以上的事件,它将起作用。我究竟做错了什么?
在收到消息后iframe可以发送命中到谷歌服务器。 –
为什么我需要跨域消息传递? iframe只显示来自同一服务器的另一个.html。这算作另一个域吗? – Koto
没有,这并不意味着跨域是源(域)和协议匹配(http/https),那么你可以简单地发送一个事件到启动谷歌分析呼叫的iframe。通过这里的例子http://www.dyn-web.com/tutorials/iframes/refs/iframe-iframe.php –