# The tracking script

The one line that tracks a website, and the calls that send purchases, leads and signups, identify the visitor and pass consent.

The tracking script collects page views on your site and sends the conversions you mark to Zernio's first-party collector. Stores set up in one click already carry it.

## First call

Paste the site's `install.snippet` before `</head>` on every page, with the line that lets you call `zernio` before the script loads.

```html
<script>window.zernio = window.zernio || function () { (window.zernio.q = window.zernio.q || []).push(arguments); };</script>
<script async src="https://edge.zernio-edge.com/z.js?s=zs_4kq9x2mzt7b1c8v3n5p6r0wa"></script>
```

Then, on your order confirmation page, send the purchase:

```js
const eventId = zernio('track', 'Purchase', {
  eventId: 'order_1042',
  value: 129.99,
  currency: 'USD',
  orderId: '1042'
});
```

The script already sent a `PageView` for the page. The purchase is stored as an event with source `web` and sent to every ad platform the site is linked to.

## Track an event

`zernio('track', name, properties)` sends one event and returns its event id.

| Property | What it is |
|---|---|
| `eventId` | Your id for the event, such as the order id. Give your browser pixel the same id so the platform counts it once |
| `value` | The amount, as a number |
| `currency` | ISO 4217 code, such as `USD` |
| `orderId` | Your order number |

Only `Purchase`, `Lead` and `CompleteRegistration` (or `generate_lead`, `sign_up`) count as conversions. Other names are kept in the site's traffic but not forwarded.

## Identify the visitor

`zernio('identify', fields)` tells Zernio who the visitor is, so ad platforms can match their conversions to a person. Call it after a login or a form submit.

```js
zernio('identify', { email: 'customer@example.com', phone: '+14155550123', externalId: 'user_881' });
```

Every later event from that visitor carries these fields. They are hashed before they reach any ad platform.

## Pass consent

The script reads Google Consent Mode v2 from `dataLayer`, both `default` and `update`. A consent banner that sets it needs nothing else.

Without one, pass the visitor's choice yourself, with the same three Consent Mode fields:

```js
zernio('consent', { ad_storage: 'granted', ad_user_data: 'granted', ad_personalization: 'denied' });
```

When `ad_storage` turns `denied`, the script forgets the visitor and click ids it kept.

## Use the event id in your pixel

Each tracked event also fires a `zernio:event` event on `window`, carrying its name and event id. Use it to fire your own pixel with the same id.

```js
window.addEventListener('zernio:event', (e) => {
  if (e.detail.name === 'Purchase') {
    fbq('track', 'Purchase', { value: 129.99, currency: 'USD' }, { eventID: e.detail.eventId });
  }
});
```

## Keep the ad click on Safari

Safari strips some click ids, such as `gclid`, from links. The tag also reads a copy under a `z` prefix, so add one to your ads' tracking:

| Platform | Add to |
|---|---|
| Google Ads | The account's final URL suffix: `zgclid={gclid}&zgbraid={gbraid}&zwbraid={wbraid}` |
| TikTok | The ad's URL parameters: `zttclid=__CLICKID__` |

Meta has no such macro. A returning Meta visitor keeps the click through the first-party cookie Zernio restores.

## Limits

| Limit | Value |
|---|---|
| Events per request | 20 |
| Request body | 16 KB |
| Requests per visitor IP | 600 a minute |
| Requests per site | 20,000 a minute |
| Event name | 64 characters |
| `eventId` | 128 characters |
| `orderId`, `email`, other text | 256 characters |
| Page URL | 2,048 characters |
| `value` | Up to 10,000,000; negative values are dropped |

Requests over a rate limit get `429` and are sent again by the tag a minute later.

## How it behaves

- **Click ids captured.** `gclid`, `gbraid`, `wbraid`, `fbclid`, `ttclid`, `li_fat_id`, `epik`, `rdt_cid`, `twclid`, OpenAI's `oppref`, AppLovin's `aleid` and `alart`, and the five UTM tags, from the landing URL.
- **Browser ids.** The tag reads the pixels' own cookies, such as `_fbp` and `_ttp`, and restores them on a return visit when the browser dropped them. The GA4 client id from `_ga` goes to Google Analytics only.
- **Content Security Policy.** Allow the collector host in `script-src` and `connect-src`, or the browser blocks the tag.
- **One page view per load.** Single-page apps that change the URL without a reload send further views with `zernio('track', 'PageView')`.
- **Sent in batches.** Events are sent together within a moment, and on leaving the page with `sendBeacon`.
- **Click ids on landing.** Ad click ids and UTM tags in the landing URL are kept and sent with later conversions.
- **Never breaks your page.** An unknown or deleted site gets an empty script, and the collector never answers with an error your page sees.

## If it fails

| Problem | Cause | Fix |
|---|---|---|
| `zernio is not defined` | You called it before the script loaded, without the first line | Add the first line of the snippet above |
| No events arrive | The page is on a host not in the site's `domains` | Add the host with `PATCH /v1/tracking-sites/{siteId}` |
| Conversions stored but not on the platform | The visitor gave no ad storage consent, or was flagged as a bot | Check Consent Mode on your banner |
| A purchase counted twice on the platform | The pixel and Zernio used different event ids | Pass the same `eventId` to both |

## Related

- [Server-side tracking](/products/server-side-tracking)
- [Use your own subdomain](/products/server-side-tracking/custom-subdomain)
- [Send events from your server](/products/conversions-api/send)