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,, but your conversion occurs on a subdomain of your site, To successfully run your experiment across multiple sub-domains, you need to make a few changes to the experiment code and to the 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 with your site's domain name):

_udn = "";

Your experiment code will look like this:

_udn = "";
<!-- Analytics Experiment code -->
... Contents of the experiment code ...
<!-- End of Analytics Experiment code -->

2. Change Your Analytics Tracking Code

If you haven't already modified your Analytics tracking code for sub-domain tracking you may want to add the _setDomainName method to your 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 Analytics tracking code.

The resulting Analytics tracking script should look like this:

<!-- Analytics Tracking Script -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXXXX-X']);
_gaq.push(['_setDomainName', '']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
<!-- End of Analytics Tracking Script -->

3. Alter the Cookie Path

By default, 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 Analytics Tracking script, then you should set the _utcp global variable with the same cookie path.

Was this helpful?
How can we improve it?