---
order: 20
---

# Counter names

Each beacon becomes a few counter names, and each name gets +1 on that day's total. The names
are what end up in your database, so they outlive any release of peepless: a stats page, a
saved query or a dashboard reads them for years. This document is their contract.
`openapi.yaml` covers what the browser sends; this covers what the server stores.

## Days

A count belongs to the day the server received the beacon, in **UTC**, written `YYYY-MM-DD`.
Days are UTC and stay UTC: there is no time zone setting, because a total split by one
time zone can't be turned into another later, and nothing finer than a day is ever kept.

## The names

| Name | +1 when | From the beacon |
| --- | --- | --- |
| `pageview` | Every page, including client-side navigations and a page restored from the back/forward cache | `event: "pageview"` |
| `visit` | The first page of a visit from another site, or from none | `visit: true` |
| `from:<source>` | On a visit: where it came from | `ref` |
| `country:<cc>` | On a visit: the visitor's country | the host's geo header, never the beacon |
| `page:<pattern>` | On a page view, when the project lists `routes` | `route` |
| `via:<tag>` | On a visit tagged `?ref=` or `?utm_source=`, when the project lists `campaigns` | `via` |
| `human` | Once per visit: the first real tap, click, key or wheel, or 10 s on screen | `event: "human"` |
| `<event>` | Each `track()` of an event the project lists | `event` |

### `from:<source>`

`<source>` is the `key` of the first entry in the handler's `sources` whose hosts match the
referring hostname, after a leading `www.` is dropped. The built-in list (`SOURCES`) has
`search`, `ai`, `reddit`, `x`, `linkedin`, `github`, `hn`, `producthunt`, `bluesky`, `facebook`
and `youtube`. Two more are always possible:

- `from:direct`: no referrer, a malformed one, or the site's own host.
- `from:other`: a referrer that matches no source.

A custom `sources` list should use keys of lowercase letters, digits and dashes.

### `country:<cc>`

`<cc>` is a lowercase ISO 3166-1 alpha-2 code (`country:us`), read from `x-vercel-ip-country`,
`cf-ipcountry` or `cloudfront-viewer-country`, or from the handler's `country` option.
`country:xx` means unknown: no header, `XX`, Tor (`T1`), or `country: () => null`.
Only visits are counted by country, so the `country:*` totals add up to `visit`.

### `page:<pattern>`

`<pattern>` is one of the project's `routes` exactly as written (`page:/blog/*`,
`page:/posts/[id]`), or `page:other` for a route the server doesn't list (including the
client's `/_other`, for a path that matched none). So the `page:*` totals add up to
`pageview` for clients that send `route`. A pattern starts with `/`, uses letters, digits and
`- _ . / * [ ]`, and is at most 100 characters.

### Your events

An event name matches `^[a-z][a-z0-9_]{0,39}$`: a lowercase letter, then lowercase letters,
digits and underscores, 40 characters at most. It can't be `pageview`, `visit` or `human`.
It contains no `:`, so it never collides with a prefixed name.

## The grammar

```
counter  = "pageview" | "visit" | "human"
         | "from:" source | "country:" cc | "page:" ( pattern | "other" )
         | "via:" ( tag | "other" ) | event
source   = [a-z0-9-]+                      ; a key of `sources`, "direct" or "other"
cc       = [a-z]{2}                        ; ISO 3166-1 alpha-2, or "xx"
pattern  = "/" [A-Za-z0-9_\-./*\[\]]{0,99}
tag      = [a-z0-9] [a-z0-9_-]{0,39}       ; a project's campaign, not "other"
event    = [a-z] [a-z0-9_]{0,39}           ; not "pageview", "visit" or "human"
```

A name is at most 105 characters (`page:` and a 100-character pattern), within the 120 that
`peepless.counts.counter` in `starters/supabase/schema.sql` allows.

### `via:<tag>`

`<tag>` is one of the project's `campaigns` exactly as written (`via:newsletter`), or
`via:other` for a tag the project doesn't list. The client sends the tag only when its own
`campaigns` list has it, and `other` otherwise, so a referral code in `?ref=` never leaves the
browser. A tag is lowercase letters, digits, `-` and `_`, at most 40 characters, and never
`other`. Counted only on a visit, so the `via:*` totals are at most `visit`.

## What a name never holds

Anything from one person. Every name is built from a list the server holds (its `sources`,
`routes` and `events`, the country codes), never from text the browser chose. A referrer the
server doesn't know becomes `from:other`; a route it doesn't list becomes `page:other`; an
event it doesn't list is refused.

## The rule from 1.0

Once peepless 1.0 is out, a name it has written to someone's table is **never renamed and never
given a new meaning**. New names may be added in a minor release (a new built-in source, say),
which changes how totals split, never what an existing name counts. Before 1.0, a change to a
name gets a line in the CHANGELOG saying what to run against existing rows.
