---
url: https://trail.karanjot.co.in/docs/tracking/privacy.md
description: >-
  Choose between private until consent, always private and full tracking, and
  wire up a consent banner.
---

# Privacy modes and consent

Trail has three modes. You pick one with an attribute on the script tag.

| | Private until consent | Private | Full |
|---|---|---|---|
| Set with | no `data-mode` (the default) | `data-mode="private"`, or load `t.p.js` | `data-mode="full"` |
| Browser storage | none until consent, then as full | none, ever | `_t_id` cookie and localStorage, from the first page |
| Visitor counted by | the server, with a daily key | the server, with a daily key | a random id in the browser |
| Journeys | from consent onwards | within one day | across days and devices |
| `identify` | upgrades to full | does nothing | works |
| Named clicks | after consent | no | yes |

## How a private visitor is counted

When the browser stores nothing, the server works out who is who. For each event it computes

```
"p_" + HMAC-SHA256(daily key, site | IP | user agent), first 22 hex characters
```

and groups that visitor's pages into sessions in memory (30 minutes idle, 24 hours at most). The daily key is 32 random bytes held only in memory and replaced at midnight in `TRAIL_TZ`. The IP and the key are never written to disk. Yesterday's key is kept until the next midnight so that a visit running past midnight stays one visitor.

As a result the same person on a different day is a different visitor, and a server restart starts every private visitor afresh. That is the price of storing nothing.

## IP addresses

Trail never stores an IP address, in any mode. The client IP is used in memory for a few things, then dropped:

* the location lookup (see [Geo database](/operations/geo));
* the per-IP rate limit, which keys its buckets by a hash under a random per-process key;
* the private-mode visitor key above;
* recognising AI agents: checking the IP against the operators' published lists, and the relay below.

When your [server hook](/add/ai-crawlers) sees a verified signed page request from an AI agent, Trail remembers `SHA-256(site | IP | user agent)` and the agent's id, in memory only, for 30 minutes, so the beacons that follow from the same browser are marked as that agent. It holds at most 10,000 entries, drops the oldest first, and starts empty after a restart. The IP itself is not kept.

## Consent

In the default mode, call `consent` from your banner:

```js
acceptButton.onclick = () => trail.consent(true);
declineButton.onclick = () => trail.consent(false);
```

* **`consent(true)`** upgrades the visitor to full mode and remembers it (`localStorage._t_c = "1"`), so later pages start in full mode. The journey starts from this moment.
* **`consent(false)`** stops all sending on this page and on later ones. It deletes `_t_id` (cookie and localStorage), `_t_s`, `_t_u` and any queued events, and keeps only `localStorage._t_c = "0"` so the choice survives the next page load.
* Calling `consent(true)` after a denial clears it and resumes.

With `data-mode="private"`, `consent(true)` never upgrades; `consent(false)` still stops sending and is remembered as above. `t.p.js` contains no storage code at all, so there `consent(false)` stops sending for the current page only.

::: info
Whether you need a banner at all depends on your site and where your visitors are, not only on Trail. In the default mode the tracker itself writes nothing to the browser before consent.
:::

## Which file to load

`t.js` holds all three modes. If you know you will never ask for consent and never want journeys across days, `t.p.js` is smaller and contains no storage code at all. See [Tracker cost](/tracking/cost) for the sizes.

Do Not Track and Global Privacy Control are covered on [their own page](/tracking/dnt).

## Next

* [Do Not Track and GPC](/tracking/dnt).
* [Identify](/tracking/identify) known users.
* Pick your framework guide under [Add to a site](/add/script-tag).
