# Cross-domain A/B testing: one experiment across multiple domains

export const metadata = guideMeta("cross-domain-tracking");

Real funnels rarely stay on one domain. Your marketing site is on
`example.com`, the app is on `app.example.com`, and checkout is on
`shop.example.com` or another domain entirely. A standard A/B test loses track
of the visitor the moment they cross that boundary. The test shows a variation,
the conversion happens somewhere else, and the two are never connected.

**Cross-domain tracking** keeps a single visitor, their assigned variation and
their conversions connected across your domains. This guide covers when you
need it, how to set it up in Testa, and how to check that it works.

## When you need cross-domain tracking

**The conversion happens on another domain.** The experiment runs on your
marketing site, but people sign up in your app or pay on a separate checkout
domain. Without cross-domain tracking, the conversion is never attributed to the
variation the visitor saw.

**The variation lives on another domain.** In a
[split URL test](/docs/experiment-setup/split-url-tests), the control is on one
domain and the variation is a page on another, for example a new landing page
built on a page builder that's hosted elsewhere.

**Multi-brand or multi-region sites.** One experiment spans `example.de` and
`example.at`, and the visitor moves between them.

If your whole funnel lives on one domain, for example `example.com` and
`example.com/shop`, you don't need this. Regular tracking already covers it.

## Setup

### 1. Install the Testa snippet on every domain

Add the Testa script to **every domain in the journey**, using the **same
project's** snippet everywhere. The script on the destination domain is what
recognizes the visitor and records conversions there.

A common mistake is creating a separate Testa project per domain. Experiments
and goals live in a project, so the visitor must stay inside one project across
all domains.

### 2. Enable Cross Domain on the experiment

In the experiment's **Advanced Settings**, turn on **Cross Domain**.

<Screenshot
  src="/images/guides/cross-domain-tracking.png"
  alt="The Enable cross-domain tracking toggle in an experiment's Advanced Settings"
  caption="Enable cross-domain tracking in the experiment's Advanced Settings."
/>

Cross-domain tracking is enabled **per experiment**. Other experiments in the
project are not affected.

### 3. Set up goals as usual

Goals need no special configuration. A page-view goal on
`checkout.example.com/thank-you` or a custom event fired in your app is
attributed to the variation the visitor saw on your marketing site.

## How it works

When a visitor moves from one of your domains to another, through a split URL
redirect or a link to your other domain, Testa adds a short identifier to the
destination URL. The Testa script on the destination domain:

1. reads the identifier,
2. recognizes the visitor and their assigned variation,
3. removes the identifier from the address bar, so it doesn't end up in
   bookmarks, shared links or your analytics.

From that point on, goal tracking works exactly as it does on a single domain.

> **Best-effort tracking**
>
> Cross-domain tracking depends on browser behavior and third-party cookie
> restrictions, so not every session can be matched across domains. It works for
> most visitors, but treat it as best-effort. Expect a small share of conversions
> on the second domain to go unattributed, equally across control and variation.

## Checking that it works

1. **Open the first domain in a private window**, so you start as a new visitor.
2. **Confirm you're in the experiment.** Use the
   [browser events](/guides/subscribing-to-events) to log your assigned
   variation to the console.
3. **Click through to the second domain.** You should briefly see an identifier
   in the URL, which then disappears.
4. **Complete the goal**, for example reaching the thank-you page or firing the
   custom event.
5. **Check the experiment's results** and confirm the conversion is attributed
   to the variation you saw.

Repeat in Safari as well as Chrome. Safari's tracking prevention is the most
restrictive, so that's where problems usually show up.

## When the other domain isn't yours

Some checkout flows go through pages where you can't install a script, for
example a hosted payment page from Stripe or PayPal. You can't track a
conversion *on* that page, but you don't need to:

- Most hosted checkouts redirect back to a **success URL on your own domain**.
  Put a [page-view goal](/docs/experiment-setup/goals) on that URL, or fire a
  `purchase` custom event there with `window.Analytica.pushEvent`.
- If the success page is on a different domain than the experiment, it's the
  same cross-domain setup described above. Install the snippet there and enable
  Cross Domain.

For Shopify checkouts, use a Customer Events pixel instead. See
[tracking Shopify checkout conversions](/guides/tracking-shopify-customer-events).

## Common pitfalls

- **Different projects on each domain.** The visitor can only be matched inside
  one project. Use the same snippet everywhere.
- **Cross Domain not enabled.** The setting is per experiment. Check it on every
  test that spans domains.
- **Redirects that strip query parameters.** If a redirect between your domains
  drops the URL query string, the identifier is lost. Make sure redirects keep
  query parameters.
- **Expecting 100% match rates.** Browser privacy features make this
  best-effort. Compare variations against each other, not against a perfect
  baseline.

## FAQ

### Do I need cross-domain tracking for subdomains?

If the journey crosses from one subdomain to another, such as `www.example.com`
to `app.example.com`, enable it and install the snippet on both. Then run the
check above to confirm conversions are attributed.

### Does cross-domain tracking affect my other experiments?

No. It only activates for experiments with **Cross Domain** enabled.

### Will the identifier show up in my analytics or SEO?

The script removes it from the address bar as soon as the destination page
loads, so it doesn't stay in the URL visitors see or share.
