Skip to main content

Google Content Experiments: Fixing Domain Validation Errors

When you set up your first Content Experiment, you might face a cookie domain name consistency error. This error is caused by using different domain name settings for Google Analytics and Content Experiments code. 

To fix the error, change the content experiment code to reflect the domain name settings used in Google Analytics Code.

Google Analytics Code

var _gaq = _gaq || [];

_gaq.push(['_setAccount', 'UA- Account Id']);

_gaq.push(['_setDomainName', '.example.com']);

_gaq.push(['_setAllowLinker', true]);

_gaq.push(['_trackPageLoadTime']);

_gaq.push(['_trackPageview']);

(function() {

      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;

      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';

      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

    })();

Google Content Experiment Code

<script>function utmx_section(){}function utmx(){}(function(){var

k='experiment-id',d=document,l=d.location,c=d.cookie;

if(l.search.indexOf('utm_expid='+k)>0)return;

function f(n){if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.

indexOf(';',i);return escape(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/ga_exp.js?'+'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><script>utmx('url','A/B');</script>

Since the Analytics code uses the format - ‘.example.com’: _gaq.push(['_setDomainName', '.example.com']), add the following code snippet above the Content Experiments Code

<script> 

_udn = ".example.com"; 

</script>  

The Final Content Experiment Code will be:

<script> 

_udn = ".example.com"; 

</script>  

<script>function utmx_section(){}function utmx(){}(function(){var

k='experiment-id',d=document,l=d.location,c=d.cookie;

if(l.search.indexOf('utm_expid='+k)>0)return;

function f(n){if(c){var i=c.indexOf(n+'=');if(i>-1){var j=c.

indexOf(';',i);return escape(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/ga_exp.js?'+'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><script>utmx('url','A/B');</script>

To use a single code for running experiments in multiple sub-domains change _udn = ".example.com" to _udn = "example.com" and _gaq.push(['_setDomainName', '.example.com']); to _gaq.push(['_setDomainName', 'example.com']);

 

If you want expert help in setting up Content Experiments for your website, contact us or you can call us at: India (Ph): +91 9497189032, UK (Ph): +44 (0)20-3371-9976 or US (Ph): +1 650-491-0004

ByteFive provides Internet Marketing Services (Search Engine Optimization (SEO), Search Engine Marketing (SEM), Develop processes and best practices for Internet Marketing, Manage and Analyze Web Analytics packages, Perform Landing page Optimization, Manage E-Mail Newsletter, Perform Competitor Research, Create & market Content, and provide customized training to help you achieve your revenue and business goals.

Subscribe to ByteFive's Newsletter