Run an Experiment

Use Cross-Domain Tracking in an Experiment

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.

If your users cross from one domain to another during the conversion process (e.g., from your shopping-cart domain to a payment-gateway domain), Content Experiments requires minor changes to the experiment code and to the Google Analytics tracking code on your pages. These tags allow information to pass between domains so that experiment users and conversions are counted correctly.

This article covers a simple alternative to cross-domain tracking, and the full implementation of cross-domain tracking.

Simple Alternative to Cross-Domain Tracking

Modifying your tracking code can present technical challenges or become time consuming. A simpler solution is to count a conversion when a user does something that initiates a cross-domain action, like clicking the check-out button, or submitting a form.

It's not quite as accurate as counting actual completed purchases, but it still provides insight into your experiment performance and how your variations affect actions leading up to a conversion.

Your experiment duration may also be reduced since you are likely to have more check-out-button clicks than conversions. You’ll collect more data in a shorter time, which can let you make decisions about website changes more quickly.

Step 1. Count a Button Click as a Conversion

To count a conversion on a button click, simply define an event that fires when the button is clicked:

<a href="http://secure.paymentexample.com" onclick="_gaq.push(['_trackEvent', 'ExperimentConversions', 'CheckOut', 'ProductPageTest1']);return false;”>Check Out</a>

Step 2. Configure Your Experiment Goal to Use the Checkout-Button Click-Event Values

You can use a configuration like the following for the goal you use in your experiment:

  • Category: ExperimentConversions

  • Action: CheckOut

  • Label: ProductPageTest1

  • Value: optional parameter and value

Full Implementation of Cross-Domain Tracking

If you are already using Google Analytics cross-domain tracking and can successfully measure conversions back to their original campaign source, then you may only need to complete Step 1.

The full implementation requires updating the Google Analytics tracking code on all domains whose pages are involved in the experiment.

In the following examples, we use example.com as the shopping-cart domain, and secure.paymentexample.com as the payment-processing domain.

Step 1. Modify the Experiment Code

Add the _udn variable before your control script. Replace example.com with the domain value you use in your experiment code:

<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 -->

If you use any of the following methods in your Google Analytics tracking code, then you may need to make additional customisations to your experiment code.

Google Analytics Tracking Code Experiment Code
_setDomainName('example.com'); _udn="example.com";
_setAllowHash(false);
This method has been deprecated.
This information is provided for legacy instances of the method.
_uhash="off";
_setCookiePath('/'); _utcp="/";

Step 2. Modify the Google Analytics Tracking Code

Your domain structure and the tracking-code-customization requirements may be different from the example below. Please be sure to review our developer documentation about tracking multiple domains before you implement any changes.

In the examples below, remember to replace:

  • UA-XXXXXXXX-X with your Google Analytics account number

  • example.com and paymentexample.com in _setDomainName with your respective top-level domain values.

example.com

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

secure.paymentexample.com

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

Step 3. Allow Cookie Information to Pass Between Domains

Depending on the method you use to trigger a cross-domain event, you may need to add the _link, _linkByPost, or _getLinkerUrl method to your link, form, or iframe (refer to developer docs for further examples).

To cross domains via an HTML link, add the _link method to the check-out button that triggers a cross-domain event:

<a href="secure.paymentexample.com" onclick="_gaq.push(['_link', 'secure.paymentexample.com']); return false;">Check out</a>

To cross domains via an HTML form submission, add the _linkByPost method to the check-out form that triggers a cross-domain event:

<form action="https://secure.paymentexample.com" onsubmit="_gaq.push(['_linkByPost', this]);">

<input type="submit" value="submit">
</form>