# Web identity: counting visitors without a cookie, and what Bucker keeps

A web project chooses how Bucker recognises a returning visitor, and what it does with the address
and the User-Agent of every request. This page is the contract. Everything here needs product
analytics turned on for the project, and no project can turn it on yet (see
[Turning on product analytics](product-analytics-gate.md)): until then every read and write below
refuses with `analytics_not_enabled` and stores nothing.

## Three identity modes

| Mode | What recognises a visitor | Session | `identify` |
| --- | --- | --- | --- |
| `cookie` (the default) | an id the SDK persists in the browser, under the project's consent basis | the SDK's | as the consent basis allows |
| `cookieless_stateless` | a key Bucker computes when the request arrives, new every UTC day | one per key per day, nothing stored for it | **never** |
| `cookieless_stateful` | the same key | 30 minutes of inactivity, in a short-lived session record purged daily | **only with consent**, flagged `consentGated` in the evidence |

The key, in both cookieless modes:

```
inner = HMAC-SHA256(salt[project, UTC day], registrableDomain ‖ UA ‖ IP)
key   = keyed pseudonym of (day ‖ inner), purpose 'visitor'          32 hex = 128 bits
```

The keyed pseudonym is the one described in [Identity and pseudonyms](identity.md). The registrable
domain makes `www.example.com` and `shop.example.com` one site (a short built-in suffix list, not the
full Public Suffix List: an unknown suffix groups one label too coarsely, which merges two sites
rather than splitting one). `::ffff:1.2.3.4` and `1.2.3.4` are one address. With no User-Agent and no
address there is no key; Bucker does not put everyone in one "visitor".

## The daily salt, and why destroying it is the feature

Each project has 128 random bits of salt per UTC day, encrypted at rest and bound to its project and
day, so a copied ciphertext does not open anywhere else. A salt is kept for its day **plus 72 hours**
(late data from an offline SDK still joins the right key) and is then destroyed: the ciphertext is
overwritten and a signed `deletion_sweep` receipt (stream `web_daily_salts`, one per organization and
day, naming the day and the project) is appended to the organization's [receipt log](receipts.md)
**at the same moment**. After that nothing can recompute a key of that day from a guess of its
inputs; and a late event for a destroyed day gets no key rather than a fresh salt, because a second
key for one day would split one visitor in two. Salts are destroyed on schedule whether or not product
analytics is still on for the project.

The day is the **UTC** day: a project has no timezone setting.

## Derive, then drop

Before the address and the User-Agent are discarded Bucker derives, and stores only:

- country (and a region only if the project set `regionResolution: region` *and* the country
  database has one),
- traffic type, category and operator, and the network class,
- browser, operating-system and device **families** (no versions).

Bucker stores no raw address or User-Agent for web analytics, and checks every derived value before it
is stored, refusing one that parses as an address or looks like a User-Agent.

### Country resolution

Countries come from the DB-IP Lite country database. **That database is not installed on Bucker's
hosted service yet**, so today every lookup answers "unknown" (a null country), including for the Vercel
log drain and for Cloudflare log-drain lines that carry no country of their own. Where the database is
not installed or cannot be read, the answer is "unknown": never a guess, and never a fallback to another
source.

The data is DB-IP Lite, CC BY 4.0. The attribution line is printed on the
[trust page](https://www.bucker.io/en/trust).

### IP-prefix retention (off by default)

`ipRetentionDays` is 0. A project may turn on retention of the IPv4 `/24` or IPv6 `/48` prefix (never a
finer address) for 1 to 30 days. Turning it **off** purges the kept prefixes and writes a signed
receipt (stream `web_ip_prefixes`) at the same moment. Bucker does not store prefixes yet, even with
the setting on, so today that receipt records zero rows purged.

## The settings, and who may change them

| Act | Registry action | Who |
| --- | --- | --- |
| Set the identity mode | `web_identity_mode.update` | a person's own session, `org:admin` (OWNER) |
| Set the IP-prefix retention | `web_ip_retention.update` | a person's own session, `org:admin` (OWNER) |

Both are human-only: an agent, a service principal, an OAuth-client token and a derived session are
refused before anything is read, and there is no MCP tool. **A change toward a longer-lived
identifier** (stateless to stateful to cookie; retention turned on or lengthened) **is a loosening and
needs a second owner** to approve it (or, in an organization with a single owner, a waiting period,
24 hours by default, after which you confirm it).
A tightening (or no change) is one owner's act, applied at once. The settings routes below never apply
a loosening on one person's say: they answer 409 `LOOSENING_NEEDS_SECOND_OWNER`. Every change is
**forward only**: sessions and keys already stored keep the mode they were written under.

## REST

```
GET /orgs/:o/projects/:p/web/settings         mode, regionResolution, ipRetentionDays, cookielessShare, tunnelledShare
PUT /orgs/:o/projects/:p/web/identity-mode    { mode, reason }
PUT /orgs/:o/projects/:p/web/ip-retention     { days, reason }
```

`cookielessShare` is the share of the last seven days' sessions counted without a cookie; the same
read feeds `web_capture_get`. `tunnelledShare` is null until Bucker records tunnelled arrivals, which
it does not do yet.
