Google analytics iframe code measuring visitor as two visitors

Posted by Maarten on Pro Webmasters See other posts from Pro Webmasters or by Maarten
Published on 2012-10-31T11:58:26Z Indexed on 2012/10/31 17:14 UTC
Read the original article Hit count: 335

Filed under:
|

I'm trying to measure visitors in an iframe and the site containing the iframe. What I would like is that visitors clicks in the iframe are seen being from the same visitor as the containing site, but somehow it is seen as two seperate visitors.

I followed examples from http://www.blastam.com/blog/index.php/2011/02/google-analytics-cross-domain-tracking/, trimmed down to an even simpler version based on the comments about setDomainName not being needed anymore but with setDomainName I get the same result: a click on a page and a click on the iframe is seen as 2 clicks by 2 seperate visitors.

This is the code in my iframe

if (_gaq && gaAccount.length > 0){
        _gaq.push(['_setAccount', gaAccount]);
        _gaq.push(['_setAllowLinker', true]);
        //_gaq.push(['_setDomainName', 'none']);
        _gaq.push(['_trackPageview', 'mytestcountername']);
    }

And this is the code in the containing page:

<script type="text/javascript">
            var _gaq = _gaq || [];
            _gaq.push(['_setAccount', 'UA-9605474-4']);
            _gaq.push(['_setAllowLinker', true]);
            //_gaq.push(['_setDomainName', '.domain.nl']);
            _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>

© Pro Webmasters or respective owner

Related posts about google-analytics

Related posts about iframe