: Duplicate Google Analytics tracking happening with iFrame My main website has the GA tracking code with subdomain tracking enabled. ga('create', 'UA-XXXXXXXX-1', 'auto'); ga('require', 'displayfeatures');
My main website has the GA tracking code with subdomain tracking enabled.
ga('create', 'UA-XXXXXXXX-1', 'auto');
ga('require', 'displayfeatures');
ga('send', 'pageview');
A subdomain has GA tracking set with the same 'UA-XXXXXXXX-1'.
My main website has an iFrame with the subdomain's page as its source. In Google Tag Assistant, I can see the same tracking code listed twice with the message 'Same web property ID is tracked twice.'
Why is it being duplicated?
More posts by @Moriarity557
1 Comments
Sorted by latest first Latest Oldest Best
There are ways around this. You can use JavaScript to tell if a site is being loaded in an iframe. There is a good thread on this here. You can use that to determine if your subdomain is loaded in an iframe and then not output the analytics code. That gets rid of the duplicate tracking issue on the main page but you still get tracking on the subdomain itself when you visit it directly.
The code in the subdomain would look something like this:
if(window.frameElement === null){
//top level element, output analytics code
}
Beware potential browser compatibility issues (the Stack Overflow thread goes into a little more detail about this)
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.