Mobile app version of vmapp.org
Login or Join
Hamaas447

: Google analytics iframe code measuring visitor as two visitors 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

@Hamaas447

Posted in: #GoogleAnalytics #Iframe

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

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Hamaas447

1 Comments

Sorted by latest first Latest Oldest Best

 

@Frith620

You need two things setup.

1) Cross domain tracking - and according to the Google Analytics docs setDomainName is needed.

2) Correct linking to your iframe:

_gaq.push(function() {
var pageTracker = _gat._getTrackerByName();
var iframe = document.getElementById('myIFrame');
iframe.src = pageTracker._getLinkerUrl('http://www.my-example-iframecontent.com/');
});


See Google Analytics docs for details and further examples: developers.google.com/analytics/devguides/collection/gajs/gaTrackingSite#trackingIFrames

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme