# How tracking works

```
creator posts  ->  /r/:linkId  ->  mint click id, record click  ->  302 out
```

One route does the measurement. There is no script to install, no pixel to
embed, and nothing running in anybody's page.

## Serving a redirect

`GET /r/:linkId` on `track.acrune.com`:

1. Looks the link up, with its campaign. An unknown code is a 404.
2. Mints an opaque **click id**.
3. Writes one `clicks` row: the account, campaign, creator and link, plus the
context below.
4. Builds the destination and answers `302`.

The whole thing is one read and one write. It is the only hot path in the
system, and it is deliberately the simplest code in it.

## Building the destination

The campaign names a `clickParam` — whatever the destination already calls its
own tracking parameter. `subid` suits most affiliate platforms;
`client_reference_id` suits a Stripe-native destination.

- If the destination URL contains the literal `{click_id}`, it is substituted
in place.
- Otherwise the parameter is set on the query string.

Any existing value of that parameter is overwritten, because a stale value
would silently misattribute every click through the link.

## The click id, and why it exists now

Nothing downstream reads the click id today.

It is minted anyway, because a click that was not identified at the time cannot
be identified afterwards. If a conversion feed ever arrives — from a payment
processor, an affiliate network, anything — the identifier is already in the
history rather than starting from the day that integration ships. It is the
cheapest available option on every future that needs one.

Conversion handling was built here once and then removed, deliberately, because
it encoded assumptions about the counterparty that were not settled. The click
id is what survives that decision.

## What a click row holds

| Column | Why |
| --- | --- |
| `ip_hash` | A salted hash, never an address. The salt is the account id, so hashes are not comparable across tenants |
| `country` | Campaign-relevant and cheap |
| `user_agent` | Raw, for classification after the fact |
| `embedded_app` | Which app's webview served the click, or null for a real browser |
| `referrer` | Where the tap came from, when the client sends one |

Nothing here identifies a person, and nothing is retained that would.

`embedded_app` earns its place because it decides what is even possible
downstream: an in-app webview cannot run Google sign-in, will not share a cookie
with Safari, and is where most organic clicks arrive from. A funnel that assumes
a real browser is a funnel that fails silently for the majority of this traffic.

## The cookie is secondary

A `acr_cid` cookie is set alongside the redirect, and it is labelled secondary
in the code for two reasons:

- Safari caps cookies written after a link-decorated arrival at one day.
- TikTok and Instagram in-app browsers are app-scoped `WKWebView`s the cookie
will never be read back from.

The parameter on the outbound URL is the mechanism. The cookie covers a return
visit in a real browser and nothing more.

## What is not measured

- **Views and impressions.** No organic platform reports them to a third
party. Anyone quoting you a view count is scraping it or estimating it.
- **Unique visitors.** Clicks are counted at-least-once; a retry, a prefetch or
a link scanner produces a row. There is no dedup on ingest today — see
[Scalability](https://acrune.com/dashboard/docs/engineering/scalability.md).
- **Conversions.** Nothing here observes what happened after the redirect.

The `post_metrics` table exists for view counts entered by hand or read from a
platform that will report them, and it is stored as snapshots rather than a
running total — the question at settlement time is "what had this delivered by
the end", and a number that has been overwritten cannot answer it.
