Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

google analytics tracking on iframe

How to track urls in iframes with Google Analytics?

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?

This should work, but it doesn't.. :(

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>
like image 477
clarkk Avatar asked Jan 22 '13 13:01

clarkk


1 Answers

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. 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..

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. 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.

like image 156
Crayon Violent Avatar answered Nov 09 '22 18:11

Crayon Violent