# The interaction stream

`$action` and `$visit` events (and the scroll depth a `$pageleave` carries) are **counted on arrival** into hourly route
counts, a click heatmap and the session's counters. **No raw interaction is stored anywhere**: an interaction is counted
and forgotten. [Heatmaps](heatmaps.md) and [analytics actions](actions-analytics.md) are read from these counts.

Nothing is counted until product analytics is on for the project, a service-wide switch for the interaction stream is
on, and a consent basis admits the session (see [the conditions](#the-conditions) below).

## What is kept

| What | Per | Holds | Retention |
| --- | --- | --- | --- |
| Hourly route counts | project, route template, hour, action kind, selector leaf | `count`, `sessions` (an approximate distinct count, standard error 0.81 %), `errorsWithin1s`, `rageCount`, `deadCount` | 90 days |
| Daily click grid | project, route template, UTC day, viewport bucket, selector chain digest, x, y on a 100 by 100 grid | `clicks`, and a 16-bucket scroll-depth histogram | 90 days |
| Session counters | the session | `actions`, `rageClicks`, `deadClicks`, `errorClicks`, `maxScrollPct` | with the session |
| Error links | issue and session | a link with `anchorMs`, for the error join below | with the issue |

Nothing holds a subject key, a URL, a query string, an input value or a coordinate pair beside a person. A route is a template
(path only); a selector is the last element of the micro-DOM chain plus a digest of the whole chain; an action name is at most
64 characters, scrubbed before it is stored, and kept only in the metadata of an error link, labelled untrusted. Counts past
90 days are deleted.

## The events

| Event | Properties read |
| --- | --- |
| `$action` | `$action_type` (`click`, `input`, `submit`, `scroll`; `custom` is not kept), `$target`, `$action_name`, `$pathname` or `$current_url`, `$viewport_width`, `$x`, `$y` (fractions of the page, 0 to 1), `$rage`, `$dead`, `$error_click`, `$scroll_pct` |
| `$visit` | `$pathname` or `$current_url`, `$viewport_width`, `$view_id`, `$tab_id`, `$scroll_pct` |
| `$pageleave` | `$pathname`, `$scroll_pct`, `$viewport_width` (only the scroll depth is read here) |
| `$exception_link` | `$exception_issue_id` (the error join) |

Viewport buckets: `mobile` under 640 px, `tablet` under 1024, `desktop` under 1536, `wide`, and `unknown` when there is no width.

## The conditions

1. **Product analytics is on for the project.** It cannot be turned on for any project yet (see
   [Turning on product analytics](product-analytics-gate.md)). While it is off, a batch carrying interaction events is
   refused with 422 `analytics_not_enabled` and nothing from it is stored; the reads refuse the same way.
2. **The interaction stream is switched on.** It is behind a service-wide switch that is off by default. Off: nothing
   is stored, nothing is claimed.
3. **Consent.** Only a basis that admits interaction storage is counted: `consent`, `contract`, `legitimate_interest`, or
   `not_required` (stored without a person). `exempt_audience` and `unknown` count nothing, because no exemption
   covers interaction data. The same rule holds for the interaction counters on the session: under a refused basis an
   `$action` or `$visit` counts as an event and moves no `actions`, rage, dead, error-click or scroll counter. Replay
   recording has its own consent handling and is not affected here.

There is no sampling: 100 % of consented sessions.

## The rate cap

A session may send 2,000 interaction events in a UTC hour. The 2,001st and later are dropped, counted as
`interaction_rate_capped` (outcome `rate_limited`, category `product`) in the project's drops, and recorded once per batch
in the product event warnings. The cap is counted per Bucker server, so after a restart, or across two servers, a session
can get more than 2,000 through in one hour.

## The error join

An interaction (click, input or submit) within 1 second before an error event, in the same session, links the error's issue
to the session with `anchorMs` (the click's time), `errorAtMs`, `kind`, `route`, `selector` and, when present, `name`, so
the issue's evidence can cite it and a replay can seek to it. The link is one per (issue, session) and keeps the first
click's `anchorMs`. The hourly route count of the click that preceded an error gets `errorsWithin1s + 1` for every error
event, so a second error after another click counts on that click; a resent error event counts nothing, because it was
already counted.

Bucker looks back over a short window of recent actions per session (the last 16). If the click and the error arrive in
separate requests, they may not be linked; the browser SDK sends a click and the error it caused in one envelope. The issue the event names must
belong to the event's own project or nothing is linked.

## Resends and erasure

Each event is counted once, so a resent event changes nothing. The counts hold no subject or session key (the distinct
count cannot be read back into sessions), so the only thing that names a session is the error link. Erasing a person
removes their error links under every pseudonym generation (see [Identity and pseudonyms](identity.md)).

## Reads

The counts are read through [heatmaps](heatmaps.md) and [analytics actions](actions-analytics.md). Reads are bounded
(90 days, 5,000 rows), and the route and selector text they return was written by your page: it is served as untrusted
when it reaches an agent.
