4

I've seen a bunch of posts on here about google analytics tracking and iframes and how there could be some issues. Also have seen this: https://developers.google.com/analytics/devguides/collection/gajs/gaTrackingSite#trackingIFrames

I have tracking code in the parent website that I don't care about, and I have tracking code in the page that's embedded in the iframe that I do care about. The iframe content is a completely different domain.

I was wondering if the iframe page will be able to get all the information about demographics and properly be able to send data up to Google for event tracking and whatnot. Again, I don't care about the parent at all in this case. Just that the google analytics code in the iframe works completely on its own.

I feel like the article I posted above from Google is relevant for users that want to somehow link the analytics in the iframe with the analytics in the parent, but I could be mistaken?

Brian
  • 7,204
  • 12
  • 51
  • 84
  • Hey Briam, did you finally make it ? if yes, how did you do it ? Because I'm looking to do the same thing as you since I don't have access to the parent page. Thanks – Miles M. Jul 17 '13 at 08:47
  • Yes, I believe I had to set P3P headers. See http://stackoverflow.com/questions/999534/ie-p3p-iframe-and-blocked-cookies-works-until-page-host-page-has-personal-inf – Brian Jul 17 '13 at 14:24

1 Answers1

4

The documentation describes exactly what you have to do. It really boils down to:

  • Load the iframe using _getLinkerUrl to link the visit inside the iframe with the visit on the top frame
  • Use P3P headers on the iframed page to work around stupid internet explorer.

I would add some notes:

  • Even if you don't care about the top level page you should add a tag into it, if you don't you can't use _getLinkerUrl and you lose the traffic source, etc. If you don't use _getLinkerUrl GA inside the iframe will think it's a brand new visit referral from the top level page.
  • Setting cookies inside an iframe, in a third-party domain is the definition of a third-party cookie. Because of that any browser that is set to block third-party cookies will block the GA cookies and GA won't work. This include Safari (both Desktop and Mobile) that are set to block third-party cookies by default. So if visits using Safari or iDevices are important for you (likely these days) this tracking won't probably give you good results. The only solution is to eliminate the iframed page, either put it in your domain or open it in a new window/tab.
Eduardo
  • 22,574
  • 11
  • 76
  • 94
  • Eduardo - I see your point about _getLinkerUrl. But I think it needs to be handled on the parent page - of which I have no control. Re: what you said about cookies. I'm performing some tests with IE at the moment. And visits are being tracked when I load up a page in IE that has my page iframed. I think I'll have to research this a bit more - as you said it just wouldn't work at all? – Brian Aug 21 '12 at 15:03
  • Ah - nevermind - I was iframing from the same domain - that's why it was working. Damn. – Brian Aug 21 '12 at 15:13