I’ve spent a lot of time reading Google Analytics documentation both official and unofficial this week, so much so that I joked I should put “ninja” or “guru” on my resume as that is so much more professional than my middle name…
If you want to track what goes on inside an iFrame when the content is hosted on a domain you don’t control, say in some 3rd party e-commerce widget there are three ways to do this with Google Analytics:
- The old way documented here in French.
- The asynchronous way which I document below.
- The analytics.js way which is the future of Google Analytics.
Besides using the Google Analytics debugger plugins, my biggest piece of advice is make sure you use the same tracking code on both domains. Tracking codes look like this UA-XXXXXXX-X, with the X’s being digits. It also helps if you have a development tracking code so your test isn’t overwhelmed by actual traffic. You also need two domains to properly test this.
This sample code works, it will fire off four tracking beacons, one for the parent, one for the iFramed content, one for the e-commerce transaction, and one for the item in the e-commerce transaction in this case two copies of “Brave New World”. If you click the link it will fire off another Google Analytics tracking event (the fifth of the session), this time it will record a play of a promotional video.
With this minimal working example hopefully you have to spend less time getting this to work in the real world.
Here is another useful example on how to properly track subdomains with Google Analytics. I’m in the process of updating all my old static content which still used urchin.js to the asynchronous tracking method. I also planned to switch my previous WordPress Google Analytics plugin to Yoast’s but something has gone wrong with “authentication”. My blog is on a subdomain. I like subdomains but they make Google Analytics and Webmaster Tools a bit more complicated.