简体   繁体   English

在iframe上进行谷歌分析跟踪

[英]google analytics tracking on iframe

How to track urls in iframes with Google Analytics? 如何使用Google Analytics跟踪iframe中的网址?

What I do is that I put this code inside the iframe, like I do on the "top" window.. But the iframe isn't tracked in analytics? 我所做的是将这些代码放在iframe中,就像我在“顶部”窗口中所做的那样..但iframe在分析中没有被跟踪?

This should work, but it doesn't.. :( 这应该工作,但它不.. :(

iframe IFRAME

<html>
    <head>
        <script type="text/javascript">
            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-35706930-1']);
            _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);
            })();
        </script>
    </head>

    <body></body>
</html>

at face value, there's no reason it shouldn't work. 从表面上看,它没有理由不起作用。 But GA will track based on the iframe URL, not the parent URL, so if the iframe is hosted on some other domain, you may have problems, depending on your settings within GA. 但是,GA会根据iframe网址而不是父网址进行跟踪,因此如果iframe托管在其他某个域上,则可能会出现问题,具体取决于您在GA中的设置。 Check to make sure you are using the right account #. 检查以确保您使用的是正确的帐户#。 Check to make sure you don't have any profile filters (such as an 'include only xyx.com' domain) or anything else in your settings that exclude domains, etc.. 检查以确保您没有任何配置文件过滤器(例如“仅包含xyx.com”域)或您的设置中排除域等的任何其他内容。

Also note that if the iframe is on a different domain, you're going to run into issues with tracking in general as far as session and visit(or) metrics. 另请注意,如果iframe位于不同的域中,那么就会话和访问(或)指标而言,您将遇到跟踪问题。 In order to get around this, you will need to implement additional cross-domain tracking . 为了解决这个问题,您需要实施额外的跨域跟踪 Not having this would not cause NO data to show up, so this in and of itself isn't the root issue. 没有这个不会导致没有数据出现,所以这本身并不是根本问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM