# Serve the tag from your domain

Forward a path of your site, such as brand.com/zt, to Zernio's collector, so its cookies last a year in Safari and blockers see your own domain.

A path on your own site makes the collector part of your pages. Your domain then sets its cookies, which Safari keeps 400 days instead of 7, and blockers see a request to your site.

## Set the path

Pick a path you do not use for pages, such as `/zt`, and send it as `proxyPath`. Keep the `secret` from the answer for your proxy.

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

```json
{
  "site": {
    "id": "6a2b3c4d5e6f7a8b9c0d1e2f",
    "proxy": { "path": "/zt", "secret": "<proxy secret>" },
    "install": { "snippet": "<script async src=\"https://brand.com/zt/z.js?s=zs_...\"></script>" }
  }
}
```

A site installed through Google Tag Manager gets the new snippet published to its container right away, so set up the forward below first. A pasted line is yours to replace with `install.snippet`.

## Forward the path

Your server sends `GET /zt/z.js` and `POST /zt/e` to `https://edge.zernio-edge.com/z.js` and `/e`. It passes the browser's `cookie`, `user-agent`, `origin` and `content-type`, and returns every `set-cookie` header.

It also adds a `Zernio-Forwarded` header, signed with the proxy secret. It carries your host, the path and the visitor's IP, country and region, so the collector judges the visitor, not your server.

```typescript
// app/zt/[...path]/route.ts (Next.js)
import { createHmac } from 'node:crypto';
import { geolocation, ipAddress } from '@vercel/functions';

const EDGE = 'https://edge.zernio-edge.com';
const SITE_KEY = process.env.ZERNIO_SITE_KEY!;
const SECRET = process.env.ZERNIO_PROXY_SECRET!;

function forwarded(request: Request): string {
  const geo = geolocation(request);
  const visit = { host: new URL(request.url).host, prefix: '/zt', ip: ipAddress(request) ?? '', country: geo.country ?? '', region: geo.countryRegion ?? '', at: Date.now() };
  const body = Buffer.from(JSON.stringify(visit)).toString('base64url');
  return `v1.${body}.${createHmac('sha256', SECRET).update(`v1.${body}`).digest('hex')}`;
}

async function forward(request: Request, path: 'z.js' | 'e'): Promise<Response> {
  const headers = new Headers({ 'Zernio-Forwarded': forwarded(request) });
  for (const name of ['cookie', 'user-agent', 'origin', 'content-type', 'if-none-match']) {
    const value = request.headers.get(name);
    if (value) headers.set(name, value);
  }
  const url = path === 'z.js' ? `${EDGE}/z.js?s=${SITE_KEY}` : `${EDGE}/e`;
  const body = request.method === 'POST' ? await request.arrayBuffer() : undefined;
  const upstream = await fetch(url, { method: request.method, headers, body });
  const answer = new Headers();
  for (const name of ['content-type', 'cache-control', 'etag']) {
    const value = upstream.headers.get(name);
    if (value) answer.set(name, value);
  }
  for (const cookie of upstream.headers.getSetCookie()) answer.append('set-cookie', cookie);
  return new Response(upstream.body, { status: upstream.status, headers: answer });
}

export const GET = (request: Request) => forward(request, 'z.js');
export const POST = (request: Request) => forward(request, 'e');
```

A Cloudflare Worker or an nginx `location /zt/` block does the same: forward the two paths and add the signed header.

## Update the snippet

Install the new `snippet` from the answer, or install the tag again through Tag Manager. It loads from `https://brand.com/zt/z.js` and sends its events to `https://brand.com/zt/e`.

## How it behaves

- **Signed or ignored.** A header that does not verify, is over five minutes old or names a host outside the site is ignored: the request then counts as your server's own, with no cookies.
- **First domain.** The snippet uses the site's first domain in `domains`.
- **New key, new secret.** Rotating the site key changes the proxy secret, so update your proxy with it.
- **Stores.** A store installed through its app keeps its own loader; the path applies to pasted tags and Tag Manager.

## Related

- [Use your own subdomain](/products/server-side-tracking/custom-subdomain)
- [Cookies and data](/products/server-side-tracking/cookies-and-data)
- [Join backend events to the visit](/products/server-side-tracking/backend-events)