Mobile app version of vmapp.org
Login or Join
Moriarity557

: 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');

@Moriarity557

Posted in: #GoogleAnalytics #GoogleSearchConsole #Tracking

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?

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Moriarity557

1 Comments

Sorted by latest first Latest Oldest Best

 

@Odierno851

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)

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme