A Unique Solution to Cross-Domain Tracking in Google Analytics
Normally, cross domain tracking is a nightmare in Google Analytics. Transferring the cookie data from one domain to another can create nightmares for companies, especially as they have to use things like:
- _getLinkerURL on iframes
- _linkByPost on all forms posting users cross domain
- _link on URLs sending users cross domain
Citricle seems to have come up with a solution (at least for sites that have their carts on a 3rd party domain name like Netsuite - but it looks simple enough to work on more complex setups). The idea is simple. To help, I’ve drawn a little diagram to explain it (seriously whipped this up in 5 minutes, certainly not winning any awards for this!):
How to set it up
All it requires are these few modifications:
1. Update your GA snippet to include the iframe creation code
2. Upload the proxy code (a blank HTML file to your site with only your GA code on it)
3. Change the value of the proxyAddress variable in the iframe creation code to the location of the proxy file on your checkout server
4. Exclude the virtual pageviews under “/tracking/citricle-ga” from your profile URLs
Iframe creation code
This code goes at the bottom of your GA snippet:
//*********************************************************************************** // Copyright 2009 Citricle. All rights reserved. // This script is released under the LGPL license which means you can use it or adapt it // to your needs, improve it and distribute it freely across the web as long as you don’t remove // this copyright notice. For technical support go to www.citricle.com. //*********************************************************************************** var domain = "roomitup.com"; //replace this with your own domain name try { if(document.URL.indexOf(domain) != -1) { if((document.referrer.indexOf(domain) == -1) && (document.referrer != "")) { var iframeElement = document.createElement("iframe"); var proxyAddress = "https://www.checkout.com/citricle-ga.html"; //replace with the location of your own shopping cart iframeElement.setAttribute("src", pageTracker._getLinkerUrl(proxyAddress)); document.getElementById("div__header").appendChild(iframeElement); iframeElement.style.display = "none"; } } } catch(e) {};
Proxy file code (on your checkout domain)
This gets uploaded to somewhere on your checkout domain. You’ll also need to replace the value for the proxyAddress in the Iframe creation code above:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Citricle Google Analytics NetSuite Proxy</title> </head> <body> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> var pageTracker = _gat._getTracker("UA-1579697-1"); //replace UA-1579697-1 with your own account # pageTracker._setDomainName("none"); pageTracker._setAllowLinker(true); pageTracker._initData(); pageTracker._trackPageview("/tracking/citricle-ga"); // You'll need to setup an exclude filter on your profile to exclude this URL </script> <p>This solution was developed by <a href="http://www.citricle.com">Citricle</a>.</p> </body> </html>
Citricle’s Original Post
Anyway, go on and checkout their solution for yourselves over at their GA/Netsuite Integration post.
Brilliant!
Why didn’t I think of this before ?
- Ophir