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?
Send Iframe Data to Google Analytics Now that everything you want to track is available in the Data Layer of your parent frame, you can send your iframe data to tools like Google Analytics.
Here's how you can add Google Analytics tracking code to your static website: Locate the JavaScript tracking-code snippet for your property, and then copy the entire snippet. Don't modify the snippet. Paste the complete snippet into the HTML on your web pages, right after the opening <head> HTML tag.
So how to use GTM for tracking of Forms Embed as Iframes: Push Data From Your Iframe to Your Parent Frame. Track iframe interactions by sending a JavaScript call "postMessage" from the iframe to the parent frame. The parent frame will listen to the call with Google Tag Manager, then forward it to your marketing tools.
Select the appropriate Account and Property, then click 'Tracking Info' in the middle column labeled 'Property'. Click 'Tracking Code' under 'Tracking Info' to access the website tracking code you'll need to install on your website. On this page, you'll see a box with multiple lines of code.
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.
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With