谷歌分析事件在iframe中不起作用

Google Analytics event not working in iframe

本文关键字:iframe 不起作用 事件 谷歌      更新时间:2023-09-26

我在客户网站上构建页面,这些页面可以是他们合作伙伴网站上的iframe
我在网站上包含了这个GA代码。

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-1494300-1']);
    _gaq.push(['_setDomainName', 'mysite.com']);
    _gaq.push(['_trackPageview']);
    (function () {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        _gaq.push(['_trackEvent', 'iframe', '/products/default.aspx', 'Petersburg- Zip Code:26847',, false]);
    })();

我已经验证了当网站从和iframe中拉入时,代码会显示并被调用。然而,我们在GA中没有得到任何事件数据。我已经阅读了iframe和GA跟踪,大多数问题似乎是跨域限制的结果。然而,有了这个实现,我不需要来自父级的任何信息,父级也不需要来自我的任何信息——我只需要事件数据。有什么想法吗?

谷歌分析依赖于cookie。从技术上讲,不同域中iframe内的Cookie是第三方Cookie。Safari默认会阻止第三方cookie。您应该仍然可以看到Chrome和Firefox用户的大部分流量,除了少数更改默认设置的用户。

对于internet explorer流量,您必须确保在iframe的响应中实施P3P Compact Policy。否则,第三方cookie也将被阻止。

阅读有关如何为Google Analytics设置P3P CP标头的更多信息。

  1. 确保没有任何过滤器过滤掉数据
  2. 确保_setDomainName中列出的域与iframe的域匹配
  3. 请确保指向正确的帐户#