I recently had to implement A/B split testing across multiple domains and sub-domains for a client and upon researching a working set-up I found that there is very little out there about this. Google’s Website Optimiser help section is frankly appalling for anyone who wants to do something slightly advanced and any information that is out there is very contradictory.
So here is the WORKING example of how to implement it.
Firstly, its key to note you cannot A/B split test across multiple domains, you have to use a multivariate test.
In this example we are testing the homepage (www.mysite.com) and we have 2 conversion pages; one on secure.mysite.com and another on secure.example.com. (If you only have one conversion page you can obviously only show the code relating to your situation).
Let’s start with the homepage:
At the very top of the page code u need to add the control script, which will look something like with:
<script type="text/javascript">// <![CDATA[
_udn = ".mysite.com"; _uhash = "0"; _ulink = "1"; function utmx_section(){}function utmx(){} (function(){var k='1234567890',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'+'ript>')})();
// ]]></script>
To ensure our cookie can be passed and tracked across our multiple domains / sub-domains we need to add some additions to the control script (these are shown in bold above).
Immediately after the control script you need to add:
<!-- utmx section name="Test URL" -->
<script type="text/javascript">// <![CDATA[
var b = utmx('variation_content', 'Test URL'); function filter(v) { var u = v[0].contents; if (b && u.substr(0,7) == 'http://' && b.substr(0, 7) != 'http://') { u = u.substr(7); } return u; } utmx('url', 'Test URL', 0, filter);
// ]]></script>
This will be used to load in our test page.
At the bottom of the homepage we then include the tracking script, but again we need to make some amendments to allow the cookie to be tracked.
<script type="text/javascript">// <![CDATA[
if(typeof(_gat)!='object')document.write('<sc'+'ript src="http'+ (document.location.protocol=='https:'?'s://ssl':'://www')+ '.google-analytics.com/ga.js"></sc'+'ript>')
// ]]></script>
<script type="text/javascript">// <![CDATA[
try { var pageTracker=_gat._getTracker("UA-1234567-1"); pageTracker._setDomainName(".mysite.com"); pageTracker._setAllowHash(false); pageTracker._setAllowLinker(true); pageTracker._trackPageview("/1234567890/test"); }catch(err){}
// ]]></script>
On our test page (page B), we need to add the same above tracking code (not control or page section script, just the above piece of code). This records which page (A or B) has been seen by a user and can therefore record a conversion against it.
Because we are using multiple domains we MUST add the _link function to our code. This is placed on all links between www.mysite.com and the domain with the conversion page (in this example secure.example.com) – you don’t need this code for sub-domains.
On www.mysite.com any links to secure.example.com would look similar to:
<a onclick="pageTracker._link(this.href);" href="https://secure.example.com/purchase.php">Click Here</a>
Without this conversions on secure.example.com will not record.
We also need to ensure that these cookies are picked up on secure.example.com. So you must ensure your Google Analytics Tracking Script (GATC) is present on secure.example.com. Again the additions are in bold, one thing to note is the changing of the parameters passed to setDomainName this needs to be mirrored in your own implementation.
<script type="text/javascript">// <![CDATA[
if(typeof(_gat)!='object')document.write('<sc'+'ript src="http'+ (document.location.protocol=='https:'?'s://ssl':'://www')+ '.google-analytics.com/ga.js"></sc'+'ript>')
// ]]></script>
<script type="text/javascript">// <![CDATA[
try { var pageTracker=_gat._getTracker("UA-1234567-1"); pageTracker._setDomainName(".example.com"); pageTracker._setAllowHash(false); pageTracker._setAllowLinker(true); pageTracker._trackPageview(); }catch(err){}
// ]]></script>
Moving on to the conversion pages:
Depending on how many you have and which site they reside on not all the following will apply to you.
The conversion page on secure.example.com contains the following code:
<script type="text/javascript">// <![CDATA[
if(typeof(_gat)!='object')document.write('<sc'+'ript src="http'+ (document.location.protocol=='https:'?'s://ssl':'://www')+ '.google-analytics.com/ga.js"></sc'+'ript>')
// ]]></script>
<script type="text/javascript">// <![CDATA[
try { var pageTracker=_gat._getTracker("UA-1234567-1"); pageTracker._setDomainName(".example.com"); pageTracker._setAllowHash(false); pageTracker._setAllowLinker(true); pageTracker._trackPageview("/1234567890/goal"); }catch(err){}
// ]]></script>
The additions are in bold and the setDomainName call is again domain specific.
The conversion page on secure.mysite.com contains the following code:
<script type="text/javascript">// <![CDATA[
if(typeof(_gat)!='object')document.write('<sc'+'ript src="http'+ (document.location.protocol=='https:'?'s://ssl':'://www')+ '.google-analytics.com/ga.js"></sc'+'ript>')
// ]]></script>
<script type="text/javascript">// <![CDATA[
try { var pageTracker=_gat._getTracker("UA-1234567-1"); pageTracker._setDomainName(".mysite.com"); pageTracker._setAllowHash(false); pageTracker._setAllowLinker(true); pageTracker._trackPageview("/1234567890/goal"); }catch(err){}
// ]]>
</script>
The difference in the 2 codes being the setDomainName call.
Now it’s time to do the online / offline validation, once thats done you need to create your variation.
Click to add a new one, enter a name (Test URL) for example. In the text box, enter the URL for page B (your test page) – single line, no whitespace. Save and preview.
You’re ready to launch
Should anyone have any questions or need some help with their set-ups I’d be more than happy to help – you can contact me via the comments.
no comments