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?

  • This is because a frameset loads the child page (your subdomain's page) in the parent page entirely, including the tracking code again, just like a mini browser window, so the pageviews will be inflated. See the bottom of this from Google: Framed sites. If you want to avoid seeing inflated pageviews, you should either remove the tracking code from the child page, setup another tracking ID for the subdomain, or create a filter to filter out the subdomain as a host from your reports.
    – dan
    Commented Jun 8, 2016 at 4:49
  • Thanks @dan, that helps. Is there a way to not have the code duplicated without using a different tracking ID for the subdomain? Commented Jun 8, 2016 at 6:58
  • No problem. As I commented above, your other choices are to remove the tracking code from the child page if it's not going to be requested or linked to directly, or create a filter as described here (use the exclude option and the subdomain in the filter pattern). As an alternative to using frames, you could use server-side scripting to include/import the child page into the parent page and strip off the JavaScript tracking code during that.
    – dan
    Commented Jun 8, 2016 at 7:11
  • Unfortunately, I can't remove the tracking code and the pages can be requested directly as well. Can I possibly create a filter to exclude JUST the Iframe data? I would need data from other pages in the subdomain for reporting purposes. Commented Jun 8, 2016 at 7:17
  • In that case see the above alternative to using a frame. I'm not sure what you mean by "iframe data", so can't suggest a filter for that.
    – dan
    Commented Jun 8, 2016 at 7:29

1 Answer 1


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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.