Using Google Website Optimizer with Multiple Domains
Monday, July 13th, 2009This blog post talks about how to use the Google Website Optimizer for A/B testing across multiple domains. Specifically the scenario is that your test pages are on one domain, but your conversion pages are on another. This is more for my own memory, but figured some others might get some use out of it too.
Google will give you basically three different bits of code:
1. The control code, which is to be placed in the top of your original page.
2. The test page tracking code.
3. The conversion page tracking code.
Google will give you the necessary Javascript code to include in your pages. However, this system relies on cookies, so when you want it to work across domains you have to make a few modifications to remove the domain name tracking and allow the cross-site linking functions to be used.
Control Script Tracking Code:
Google will give you some code similar to the following which should be placed at the top of your original page:
<script>
function utmx_section(){}function utmx(){}
(function(){var k='2772144706',d=document,l=d.location,c=d.cookie;function f(n){
if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.indexOf(';',i);return c.substring(i+n.
length+1,j<0?c.length:j)}}}var x=f('__utmx'),xx=f('__utmxx'),h=l.hash;
d.write('<sc '+'ript src="'+
'http'+(l.protocol=='https:'?'s://ssl':'://www')+'.google-analytics.com'
+'/siteopt.js?v=1&utmxkey='+k+'&utmx='+(x?x:'')+'&utmxx='+(xx?xx:'')+'&utmxtime='
+new Date().valueOf()+(h?'&utmxhash='+escape(h.substr(1)):'')+
'" type="text/javascript" charset="utf-8"></sc>')})();
</script><script>utmx("url",'A/B');</script>
You need to add the three lines at the top:
<script>
_uhash = “off”;
_ulink =”1″;
_udn =”none”;
function utmx_section(){}function utmx(){}
(function(){var k=’2772144706′,d=document,l=d.location,c=d.cookie;function f(n){
if(c){var i=c.indexOf(n+’=');if(i>-1){var j=c.indexOf(’;',i);return c.substring(i+n.
length+1,j<0?c.length:j)}}}var x=f(’__utmx’),xx=f(’__utmxx’),h=l.hash;
d.write(’<sc ‘+’ript src=”‘+
‘http’+(l.protocol==’https:’?’s://ssl’:'://www’)+’.google-analytics.com’
+’/siteopt.js?v=1&utmxkey=’+k+’&utmx=’+(x?x:”)+’&utmxx=’+(xx?xx:”)+’&utmxtime=’
+new Date().valueOf()+(h?’&utmxhash=’+escape(h.substr(1)):”)+
‘” type=”text/javascript” charset=”utf-8″></sc>’)})();
</script><script>utmx(”url”,’A/B’);</script>
Test Page Tracking Code:
Google will give you some code similar to the following which should be placed at the bottom of your test pages (including the original):
<script type="text/javascript">
if(typeof(_gat)!='object')document.write('<sc '+'ript src="http'+
(document.location.protocol=='https:'?'s://ssl':'://www')+
'.google-analytics.com/ga.js"></sc>')</script>
<script type="text/javascript">
try {
var pageTracker=_gat._getTracker("UA-XXXXXXX-X");
pageTracker._trackPageview("/nnnnnnnnnn/test");
}catch(err){}</script>
You need to add three lines before the trackPageview call:
<script type="text/javascript">
if(typeof(_gat)!='object')document.write('<sc '+'ript src="http'+
(document.location.protocol=='https:'?'s://ssl':'://www')+
'.google-analytics.com/ga.js"></sc>')</script>
<script type="text/javascript">
try {
var pageTracker=_gat._getTracker("UA-XXXXXXX-X");
pageTracker._setDomainName(”none”);
pageTracker._setAllowLinker(true);
pageTracker._setAllowHash(false);
pageTracker._trackPageview(”/nnnnnnnnnn/test”);
}catch(err){}</script>
Converstion Page Tracking Code:
Google will give you some code similar to the following which should be placed at the bottom of your conversion pages:
<script type="text/javascript">
if(typeof(_gat)!='object')document.write('<sc '+'ript src="http'+
(document.location.protocol=='https:'?'s://ssl':'://www')+
'.google-analytics.com/ga.js"></sc>')</script>
<script type="text/javascript">
try {
var pageTracker=_gat._getTracker("UA-XXXXXXX-X");
pageTracker._trackPageview("/nnnnnnnnnn/goal");
}catch(err){}</script>
You need to add three lines before the trackPageview call:
<script type="text/javascript">
if(typeof(_gat)!='object')document.write('<sc '+'ript src="http'+
(document.location.protocol=='https:'?'s://ssl':'://www')+
'.google-analytics.com/ga.js"></sc>')</script>
<script type="text/javascript">
try {
var pageTracker=_gat._getTracker("UA-XXXXXXX-1");
pageTracker._setDomainName(”none”);
pageTracker._setAllowLinker(true);
pageTracker._setAllowHash(false);
pageTracker._trackPageview(”/nnnnnnnnnn/goal”);
}catch(err){}</script>
Making your links trackable:
Once you have the code setup to allow tracking through the links (setAllowLinker code) you need to make sure the links from your test page to your other domain are tracked. Be careful not to miss links, if you do miss links it is possible for people to be tracked as a visitor but not as converted even if they convert. This would result in missing some conversions and could make your test give you a false result.
Original Link:
<a href="http://www.linktoanotherdomain.com">Test Link</a>
Modified Link:
<a href="http://www.linktoanotherdomain.com" onclick="javascript:pageTracker._link(this.href); return false;">Test Link</a>
That’s all there is too it, unless your situation is a little more complicated, like mine was. I my case my tracked links didn’t point to my second domain because all of the links go through a script that does a 302 redirect. So I had to do one more step.
Passing Tracking Through Redirects:
So in my case the test page actually linked to a page on the same domain. That page does some work, then redirects the user with a 302 redirect to the success page on the second domain. So the link code correctly formulated the link, but my redirect script had to be smart enough to pass it along again. The google javascript linker code basically adds a few query string parameters to the URL. You basically have to just pass these along again as your redirect to the second domain. I found that I need to get the following parameters from the query string and add them to my redirect url to my conversion page: __utma, __utmb, __utmc, __utmx, __utmz, __utmv, __utmk (yes that is two _ in front of the variable names).
That’s it, then test your experiment to make sure it is working. Remember, data will take hours to appear after you have done you testing.
Tweet This