views:

6009

answers:

4

Our company runs a web site (oursite.com) with affiliate partners who send us traffic. In some cases, we set up our affiliates with their own subdomain (affiliate.oursite.com), and they display selected content from our site on their site (affiliate.com) using an iframe.

Example of a page on their site:

<html>
<head></head>
<body>
<iframe src="affiliate.example.com/example_page.html">
...content...
[google analytics code for affiliate.oursite.com]
</iframe>
[google analytics code for affiliate.com]
</body>
</html>

We would like to have Google Analytics tracking for affiliate.oursite.com. At present, it does not seem that Google is receiving any data from the affiliate when the page is loaded from the iframe.

Now, there are security implications in that Javascript doesn't like accessing information about a page in a different domain, and IE doesn't like setting cookies for a different domain.

Does anyone have a solution to this? Will we need to CNAME the affiliate.oursite.com to cname.oursite.com, or is there a cleaner solution?

+5  A: 

1, You have to append the Google Analytics tracking code to the end of example_page.html. The content between the iframe - /iframe tag only displays for browsers, which do not support that specific tag.

2, Should you need to merge the results from the subdomains, there's an excellent article on Google's help site (How do I track all of the subdomains for my site in one profile? )

Silver Dragon
A: 

Sorry, but it's not going to work. The reason is because Google Analytics uses first-party cookies. This means the cookies that GA sets are specific to the domain the code is on. In your case, the iFrame is on a third-party domain. This means you're going to have two sets of GA cookies (one set for each domain), and no real way to reconcile the data.

Chris
A: 

Question though. Will the iframed site track correctly, regardless of the sub-domain stuff?

I'm imagining this for my particular scenario:

1) My site has another site in an iframe showing on it. 2) My site has google analytics on it (outside of the iframe tag). 3) This other site that is showing in the iframe also has google analytics on it.

A) will my site track pageviews of this page on our site correctly? B) MORE IMPORTANTLY, will the iframed site track pageviews correctly, and will it track conversions taking full use of cookies, or will cookies not work while the other site is in an iframe?

A: 

Hey there

In the specidic case of iframes, google doesn't say much. I've been in the same situation but I'm glad I figured it out. I posted a walktrhough in here. It's in French but you won't need to speak the language to copy / paste the code. Plus there's a demo file you can download.

Hopefully this'll be helpful for some. Greg

Gregory Raby