# Cross-domain tracking

> Follow one visitor from your marketing site to your app or checkout on another root domain, so revenue is credited to the source that started the visit.

Subdomains of your website's domain already share one visitor (see [Track subdomains](https://reveata.com/docs/subdomains)). When a visit moves to a different root domain, for example from `example.com` to `example-app.io`, browsers keep their cookies apart, so without help the second domain would see a new visitor arriving from a referral. Cross-domain tracking carries the visitor along.

## 1. Add the other domain to the website

In Reveata, open the website's **Settings → General → Additional domains** and add the other root domain, for example `example-app.io`. Subdomains of each added domain are included. A website can have up to 20 additional domains.

This tells Reveata that events from `example-app.io` belong to this website. Without it, they are refused as coming from another site.

## 2. List the domains in the snippet

Use the same snippet on both domains, with `data-domains` listing the other root domains of the website (comma separated):

```html
<!-- on example.com -->
<script
  defer
  data-website-id="ws_your_tracking_id"
  data-domains="example-app.io"
  src="https://reveata.com/js/script.js"
></script>

<!-- on example-app.io -->
<script
  defer
  data-website-id="ws_your_tracking_id"
  data-domains="example.com"
  src="https://reveata.com/js/script.js"
></script>
```

With the npm packages, pass `domains: ['example-app.io']` to `init()` or to the Next.js component.

## How it works

When a visitor clicks a link to one of the `data-domains`, the script adds a short `_dt` parameter to that link at the moment of the click. It holds the visitor id, the session id, the visit number and the time of the click.

On the other domain, the script accepts those ids only when all of these are true:

- the link is less than 2 minutes old,
- the page was opened from one of its own `data-domains` (the browser's referrer says so),
- the ids are well formed.

It then stores them in its own cookies and removes `_dt` from the address bar, so the parameter is not bookmarked or shared. A copied or old link carries no identity: it simply starts a new visitor. That keeps someone from pasting a link that makes a stranger look like them.

Pageviews on the second domain then continue the same session, keep the original source and campaign, and a payment made there is credited to them.

## Limits

- **Only real link clicks are decorated.** Navigation started from code (`window.location = …`, a form that posts to the other domain, a redirect from your server) carries no ids. Use an `<a href>` link for the hand-off where you can.
- **The referrer must reach the other domain.** A `Referrer-Policy: no-referrer` header or `rel="noreferrer"` on the link removes it, and the ids are ignored. The browser default (`strict-origin-when-cross-origin`) works.
- **Cookieless mode** stores no ids, so there is nothing to pass on. Visits on both domains are joined only when the server-derived daily id matches (same address and browser on the same day).
- **Checkout pages you don't control**, such as a payment provider's hosted checkout, are not part of this. Payments from them are linked through the checkout itself: see [Connect a payment provider](https://reveata.com/docs/connect-a-payment-provider).

## Check it works

1. Open your first domain in a private window from a link ending in `?ref=crossdomain-test`.
2. Click a link to the other domain.
3. In Reveata, open **Realtime**: you should see one visitor whose pages span both domains. In the **Pages** panel's **Hostname** tab both hosts appear, and the visit keeps `crossdomain-test` as its source.

If the second domain shows a new visitor from a referral, check that both snippets list each other in `data-domains`, that the other domain is under **Additional domains**, and that the link is a plain link without `rel="noreferrer"`. Add `data-debug="true"` to the snippet to see in the console what the script does.
