# Web analytics: rollups, freshness, channels and the registry

Web analytics in Bucker is counted on arrival and recomputed on a schedule. Nothing here reads a raw
event: an accepted `$pageview` is counted into an hourly rollup and dropped, and everything a
session says (sessions, bounces, duration, uniques, entry and exit, channel, UTM fields) is
recomputed from the per-session records.

Web analytics 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)). The web rollups are also behind a
service-wide switch that is off by default. With either off, nothing is stored.

## Rollups

| Bucket | Grain | Kept |
| --- | --- | --- |
| Hourly | one row per project, site, UTC hour, dimension kind and value | 13 months (396 days) |
| Daily | the same shape per UTC day | at most 25 months (760 days), the CNIL and AEPD cap on audience-measurement data |

Each row holds pageviews, sessions, bounces, summed duration, bot pageviews, goal conversions, the
consent-basis mix, a visitor sketch, and the classifier and channel versions it was computed under.
Every hourly and daily bucket states `computedAt` and `lateEvents` (events that arrived more than an
hour after the bucket closed and were still counted in it).

Dimensions: `total`, and, per hour, `channel`, `device_class`, `traffic_type`, `country` (top 50),
`consent_basis`, and the high-cardinality `path`, `entry_path`, `exit_path`, `referrer_domain` and UTM
fields (top 100 values an hour, counts only, the rest folded into `$other` with the total kept
exact; top 500 a day). Crawlers are counted as bot pageviews on the `total` and `traffic_type` rows
and never in pageviews.

## Uniques are approximate, and say so

Visitors are a HyperLogLog sketch of keyed visitor pseudonyms, precision 12 on a totals row
(standard error about 1.6%) and precision 10 on a low-cardinality dimension (about 3.3%). A day
sketch is built from the day's own sessions, so a returning visitor counts once. A range of 24 hours
or less answers from the most recent data and is exact; the evidence block says which tier answered.

## Freshness: the recompute schedule

| Window | Recomputed |
| --- | --- |
| the current hour | every 5 minutes |
| the previous 6 hours | hourly |
| the last 7 days | nightly (expired data is removed at the same time) |

A recompute replaces the session figures of a bucket (sessions, bounces, duration, uniques, the
consent mix) and keeps the pageview counts recorded as events arrived. Only projects with product
analytics on are recomputed, and one project failing never holds up the others.

`computedAt` on a row is the time of its last write, whether by an arriving pageview or by a
recompute: a pageview counted a minute ago makes it recent even when the session figures were last
recomputed at an earlier step of the schedule.

## Erasure

A sketch cannot subtract a visitor, so erasing a person is a rebuild. Bucker notes every hour and
day the person's sessions started in, deletes the sessions as part of the erasure request, and then
recomputes exactly those buckets, whatever their age and whether or not product analytics is still
on for the project. Afterwards no row carries the person's sessions, bounces, duration, consent
basis or any part of the visitor sketch they set. Pageview counts recorded from events stay: they
are counts that name nobody.

## Channels

The channel of a session is stored per rule-set version, so a new release of Bucker's channel rules
is a recompute of sessions, never a re-read of events. A release that would move more than 2% of a
project's last 30 days (each of the project's human sessions of the last 30 days, classified under
both versions) runs in shadow for that project for 24 hours: the project keeps classifying under the
version it had, with a before-and-after notice, and the new version takes effect when the 24 hours are
up. A release that moves less takes effect at once.

## The attribution registry

`GET /web/attribution-registry` serves the registry the SDK and Bucker parse a landing with
(UTM fields and aliases, click ids, in-app browser rules): public, cacheable for an hour, `ETag` is
the sha256 of the document as served. It carries no tenant data and no input. When no registry is
installed the route answers 503 `attribution_registry_unavailable` rather than an empty document.

## The evidence block

Every web read carries a `web-evidence/1` block: tier, approximate uniques and error, `computedAt`,
`lateEvents`, bucket, requested and applied timezone (non-integer offsets are refused), classifier
and channel versions, consent counts, sources, and a digest. Free text inside it is listed as
untrusted.

## Export

`WEB_SESSION_ROLLUPS` (bucker-schema `WEB_SESSION_ROLLUPS@1`) exports the hourly rows to a
warehouse, paged by `(computedAt, recordId)`; a recomputed bucket is re-exported.
