> AI agents: this is one page of nextanalytica's docs. The full index for agents: https://nextanalytica.app/llms.txt

# Subdomains, domains and Safari

> Keep one visitor across your subdomains and your other domains, and stop Safari from forgetting returning visitors after 7 days.

Updated: 2026-11-18

After a visitor agrees, the tag keeps one id for them, `na_id`, so their visits on different days make one person. This page covers keeping that one person when they move between your subdomains and your other domains, and in Safari, which forgets a script's cookie after 7 days.

Before consent none of this applies: the tag keeps nothing on the device. See [Cookieless counting and consent](/docs/tracking/cookieless-and-consent).

## Do my subdomains share one visitor?

Yes, with nothing to set up. The tag keeps `na_id` in a cookie on your site's own domain, so `www.shop.example`, `app.shop.example` and `shop.example` all see the same visitor. A second cookie, `na_d`, holds that domain.

> **Note:** On `localhost` or an IP address, the cookie stays on that one host.

## How do I link my other domains?

When one project spans two domains, such as a store on `shop.example` and checkout on `pay.example`, list the other domain on the tag line of each site. Both lines use the same project key.

On `shop.example`, the line lists `pay.example`:

```html
<script async src="https://t.nextanalytica.app/t.js" data-project="na_…" data-domains="pay.example"></script>
```

On `pay.example`, it lists `shop.example`:

```html
<script async src="https://t.nextanalytica.app/t.js" data-project="na_…" data-domains="shop.example"></script>
```

With the npm package, pass `domains`:

```tsx title="app/layout.tsx"
<Analytics project="na_…" domains={["pay.example"]} />
```

After a yes, a link to a listed domain carries the visitor's id for **2 minutes**, in a `_na` parameter. The tag on the other side takes it as the visitor's own id once that visitor agrees there too, and removes `_na` from the address before the page view is sent. Without consent, links carry nothing.

> **Note:** Only links carry the visitor. A form posted to the other domain, or a redirect your code makes, starts a new visitor there.

## Why does Safari count returning visitors as new?

Safari keeps a cookie that a script writes for **7 days** at most. A visitor who comes back after two weeks gets a new `na_id` and counts as someone new.

A cookie your own server sets keeps its full time. The `@nextanalytica/tag/server` helper renews `na_id` on every page your server sends, for **13 months**. It only renews an id the tag already made after consent, and never sets one of its own. It also adds `na_s`, which tells the tag to leave the cookie to your server.

For Next.js, renew in the middleware:

```ts title="middleware.ts"
import { NextResponse, type NextRequest } from "next/server";
import { renew } from "@nextanalytica/tag/server";

export function middleware(req: NextRequest) {
  const res = NextResponse.next();
  renew(req, res.headers);
  return res;
}
```

For SvelteKit, renew in the server hook:

```ts title="src/hooks.server.ts"
import { renew } from "@nextanalytica/tag/server";

export const handle = async ({ event, resolve }) => {
  const res = await resolve(event);
  renew(event.request, res.headers);
  return res;
};
```

For any other server, `renewCookies` returns the `Set-Cookie` values to add to a page's response. Here it is in Express:

```js title="server.js"
import { renewCookies } from "@nextanalytica/tag/server";

app.use((req, res, next) => {
  if (req.accepts("html")) res.append("Set-Cookie", renewCookies(req.headers.cookie, req.headers.host));
  next();
});
```

> **Note:** The cookie must come from the server that answers for your site's address. Safari still keeps a cookie for 7 days when it comes from a server at another company's address.

## Next steps

- [Identify people](/docs/tracking/identify-people) to join a signed-in person's devices.
- [Tag JavaScript API](/docs/reference/tag-api) for every attribute of the tag line.

Canonical address: https://nextanalytica.app/docs/tracking/cross-domain
