Run an Experiment

Run an Experiment Across Subdomains

This information applies to the Classic Analytics JavaScript (ga.js) only. Find out if you’re using Classic or Universal Analytics or learn how to upgrade from Classic Analytics to Universal Analytics.

Suppose you are running a test on your main page, www.example.com, but your conversion occurs on a subdomain of your site, checkout.example.com. To successfully run your experiment across multiple sub-domains, you need to make a few changes to the experiment code and to the Google Analytics tracking code.

1. Change Your Experiment Code

For your experiment with multiple sub-domains, you need to add this code just before the experiment code on your original page (replace example.com with your site's domain name):

<script>
_udn = "example.com";
</script>

Your experiment code will look like this:

<script>
_udn = "example.com";
</script>
<!-- Google Analytics Experiment code -->
... Contents of the experiment code ...
<!-- End of Google Analytics Experiment code -->

2. Change Your Google Analytics Tracking Code

If you haven't already modified your Google Analytics tracking code for sub-domain tracking you may want to add the _setDomainName method to your Google Analytics tracking code on all pages of your site.

In your experiment code, the value of _udn should always match the value of _setDomainName in your Google Analytics tracking code.

The resulting Google Analytics tracking script should look like this:

<!-- Google Analytics Tracking Script -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_setDomainName', 'example.com']);
_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);
})();
</script>
<!-- End of Google Analytics Tracking Script -->

3. Alter the Cookie Path

By default, Google Analytics sets the cookie path to the root level (/). However, if you altered the location of the cookies by setting a sub-directory as the default path for all tracking using _setCookiePath for your Google Analytics Tracking script, then you should set the _utcp global variable with the same cookie path.