# Use your own subdomain

Serve the tracking script from a subdomain of your site, such as t.brand.com, with one CNAME record.

By default the script loads from Zernio's collector host. A subdomain of your own makes the collector part of your site, so it can keep the visitor's ids in server cookies on your domain.

## Set the subdomain

Pick a subdomain you do not use for pages, such as `t.brand.com`, and send it as `customHostname`. In the dashboard, it is **Your own subdomain** on the site.

```bash
curl -X PATCH "https://zernio.com/api/v1/tracking-sites/6a2b3c4d5e6f7a8b9c0d1e2f" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "customHostname": "t.brand.com" }'
```

```json
{
  "site": {
    "id": "6a2b3c4d5e6f7a8b9c0d1e2f",
    "customHostname": {
      "hostname": "t.brand.com",
      "status": "pending",
      "dnsRecord": { "type": "CNAME", "name": "t", "target": "edge.zernio-edge.com" }
    }
  }
}
```

## Add the DNS record

At your DNS provider, create the record in `customHostname.dnsRecord`: a `CNAME` named `t`, pointing to `edge.zernio-edge.com`. On Cloudflare, leave the proxy off.

Zernio checks every hour, or at once with **Check now**. Once the certificate is issued, `status` turns `active` and `install.snippet` loads from your subdomain.

## Update the snippet

On a site where you pasted the line, replace it with the new `install.snippet` from `GET /v1/tracking-sites/{siteId}`. The old one keeps working, without server cookies.

## Remove the subdomain

Send `null` to go back to Zernio's host. Put the default snippet back on your site first.

```bash
curl -X PATCH "https://zernio.com/api/v1/tracking-sites/6a2b3c4d5e6f7a8b9c0d1e2f" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "customHostname": null }'
```

## How it behaves

- **Subdomains only.** The hostname must be under one of the site's `domains`, and cannot be a domain the site serves pages on.
- **Safari's limit.** Safari keeps cookies set through a CNAME for 7 days, so a returning Safari visitor may get new ids after a week.
- **One site per hostname.** Two sites cannot share a subdomain.

## If it fails

| Error | Cause | Fix |
|---|---|---|
| 400 `invalid_field_value` | The hostname is not a subdomain of the site, or is the site itself | Pick a subdomain such as `t.brand.com` |
| 409 `custom_hostname_taken` | Another site uses it | Pick another subdomain |
| `status` is `failed` | The CNAME was missing or wrong when Zernio checked | Fix the record, then send the same `customHostname` again |
| 502 `provider_unavailable` | The subdomain could not be registered for now | Try again in a few minutes |

## Related

- [Server-side tracking](/products/server-side-tracking)
- [The tracking script](/products/server-side-tracking/script)