Skip to Content
ReferenceRegion-aware observability policy

Region-aware observability policy

Status: implemented and off by default. I have confirmed default-on collection across the United States and Canada; counsel has not reviewed it. Issue: #572. Epic: #537. ADR: 0002. Parent design: ADR 0001 and the architecture spec.

What ships

A policy layer that decides, per visitor, which optional purposes may run without an opt-in. It composes with the consent controller (#547) and does not replace it.

  • NEXT_PUBLIC_ANALYTICS_REGION_POLICY is off unless set to on. Off means no extra request and the consent-only behavior of ADR 0001 everywhere.
  • With the flag on, visitors in the United States and Canada run every capability the build lists in NEXT_PUBLIC_ANALYTICS_CAPABILITIES without an opt-in, and see no privacy control at all. Visitors in the EU/EEA, the UK, Switzerland, any other country, or an unknown location stay consent-required.
  • A default-on outcome is ignored unless its regime has a review (reviewer, date, reference). The resolver enforces that, so editing a basis alone cannot turn collection on.

The baseline (cookieless, aggregate) is untouched and still runs for everyone.

Decision order

For each optional purpose, resolveCollectionPolicy evaluates in this order. The first rule that applies decides.

  1. Do Not Track or Global Privacy Control is set: off.
  2. A kill switch removes the purpose: off.
  3. The region blocks the purpose (disabled basis): off, even with an opt-in.
  4. The visitor has a current decision: that decision.
  5. The visitor has an older decline or a revocation: off. A decline made under an earlier policy version still counts as a decline. A grant under an earlier version does not count as a grant.
  6. No decision: the region’s default-on result, which is off unless the regime is reviewed and approved.

Feature flags and PostHog remote settings sit below all of this. buildSdkConfig pins person_profiles, advanced_disable_flags, disable_surveys, heatmaps and dead clicks in code, and a test asserts that no combination of running capabilities changes them.

The matrix

Source: src/lib/analytics/region/matrix.ts. Version 2, effective 2026-10-31. Rows are regimes, columns are the eight capabilities in capabilities.ts, and each cell is default-on, consent-required or disabled.

RegimeMaps fromBasis in forceReview
eu-eeaEU member states, Iceland, Liechtenstein, Norwayconsent-requirednone
ukGBconsent-requirednone
switzerlandCHconsent-requirednone
us-state-lawUS states with a broad consumer privacy law (list)default-onowner confirmation, 2026-10-31
us-otherother US states, and US signals with no statedefault-onowner confirmation, 2026-10-31
canadaCA, all provinces and territoriesdefault-onowner confirmation, 2026-10-31
otherany other countryconsent-requirednone
unknownno signal or a malformed signalconsent-requiredn/a, never default-on

The review on the three default-on rows is my confirmation, recorded in the code as “Not a review by counsel”. The two US rows now have the same outcome. The split stays so that a later review can treat them differently without a code change.

The state list lives in classify.ts. It has no effect on the outcome today.

Person profiles are not a column: ADR 0001 keeps person_profiles at identified_only, and adding always needs its own approval.

An IP-derived country says where a connection appears to come from. It does not establish which law governs the processing. I have confirmed that default-on collection is acceptable across the United States and Canada. These points stay with me or counsel, and the code does not decide any of them:

  • Quebec’s private-sector law and any provincial rules sit inside the Canada row. Replay and other behavioral capture are inside the default-on scope too, as the confirmation covers every capability. Narrowing either is a change to one row or cell in the matrix.
  • Whether the absence of an in-site opt-out, beyond Global Privacy Control and Do Not Track, meets each state’s requirements for the capabilities in use. Where the row is default-on the privacy panel and footer link are not rendered (see below).
  • Whether the site targets or monitors people in the EU, UK or Switzerland, which brings GDPR or UK GDPR into scope for visitors there regardless of where I sit. Those rows are consent-required.
  • Whether a first-party proxy, cookieless mode or anonymized labels change the analysis. The code assumes they do not.
  • Cross-border transfer terms for events sent to PostHog US cloud, and retention (see Retention, access and cost).

Resolving the region

GET /api/region returns { country, subdivision } read from Vercel’s x-vercel-ip-country and x-vercel-ip-country-region headers, each validated against a strict pattern. It never reads, logs or returns the IP address, the city or any other header. The response is private, no-store, because the CDN keys a cache by path and a shared copy would hand one visitor another’s region. Off Vercel, and in development, the headers are absent and the answer is unknown.

On the client, startRegionPolicy requests it once when the provider module loads, with no cookies, no referrer and no cache.

  • The answer lives in memory. Nothing is written to the browser, so there is no stored region to reset or to expire by hand.
  • It is trusted for 30 minutes. Then it is requested again. While the request is in flight the old effect holds, so an unchanged visitor keeps one anonymous ID. A failed or malformed answer replaces the old effect with none.
  • Every failure (offline, blocked by an extension, slow, malformed) leaves no effect, which is the consent-only behavior.
  • SDK start waits up to 1.5 seconds for the first answer, so persistence starts with the right setting. The stored-identifier sweep that runs at startup waits for the answer too; otherwise it would delete the identifier of a visitor the region lets run by default.
  • SPA navigation does not change the answer. The provider module runs once per full page load.

VPN and proxy uncertainty

A VPN or proxy can place the connection in a different region from the visitor. The code covers one direction: when the signal would be permissive and the browser’s time zone is in Europe/, Atlantic/ or Arctic/, or is unavailable, the result is conflicting-location and falls back to consent. The check over-includes on purpose (it also catches Istanbul and Moscow). It cannot catch a visitor in, say, Brazil on a US VPN. That residual risk goes to the reviewer along with the proposal.

Notice and privacy choices

  • Where the region runs every purpose the build offers by default, the first-visit notice, the privacy panel and the footer link “Privacy settings” are not rendered for a visitor who has made no choice. There is no in-site way to opt out for that visitor. Global Privacy Control and Do Not Track still turn the optional purposes off.
  • While the region answer is pending, the controls are held back so they do not flash. If the answer fails or says consent-required, they appear as in ADR 0001.
  • A visitor with a stored choice keeps the footer link and can change it. A stored decline wins over the region default, including after a policy version bump.
  • Where only some offered purposes are default-on, the panel shows those switches on with a note, and the notice asks about the rest.
  • Withdrawal, reset and deletion follow the existing flows (ADR 0001, Revocation, reset and deletion). Without a rendered panel, a visitor in a default-on region can reach those only by contacting the owner.

Test map

Acceptance areaWhere
Classification, conflict, review gating, foldsrc/lib/analytics/region/region.test.ts
Decision order, GPC, DNT, kill switch, stale choicesrc/lib/analytics/consent/collectionPolicy.test.ts
Late answer, identifier sweep, stored declinesrc/lib/analytics/consent/runtime.test.ts
Route output, header validation, no cachingsrc/app/api/region/route.test.ts
Flags and SDK settings cannot move the pinssrc/lib/analytics/client/sdkConfig.test.ts
Panel text and switches in a default-on regionPrivacySettings.test.tsx, story DefaultOnForRegion
Outgoing payloadspnpm probe:analytics-payloads, run with the flag off. See “What I have not verified” below.

Cost

Measured on 2026-10-31:

  • Client code: the matrix, classifier, resolver and store minify to 2.9 KB, 1.5 KB gzipped. start.ts adds a small fetch loop that shares the consent runtime already in the bundle; it was not measured on its own.
  • One extra request per full page load when the flag is on, to a first-party route of about 40 bytes. Nothing when it is off.
  • SDK start can wait up to 1.5 seconds for that request. The SDK already loads after first paint on idle, so first paint and Largest Contentful Paint do not wait on it.

Not measured: startup and latency against the #556 budget in a production build, ingestion volume, and replay cost. Default-on analytics would raise event volume above the opt-in-only figure; the guardrails in Volume and cost guardrails apply and need re-checking with real traffic.

Compatibility with the stack

Merged work is unchanged in behavior. Additions are additive adapters.

IssueInteraction
#546ADR 0002 extends ADR 0001 and records the region layer
#547resolveCollectionPolicy takes an optional region input. Without it the function is as before
#548Panel gains a defaultOn prop and two strings
#549buildSdkConfig is unchanged. Running capabilities still derive from the folded policy
#538, #540They keep their acceptance criteria. Default-on persistence or replay reaches them only through the policy
#550, #551Event stage and revocation unchanged
#555, #560Add a region-on case to the payload probe and the end-to-end matrix before rollout
#556, #559Budget measurement and canary gates are required before the flag is set in production

No issue descriptions were edited.

Rollout and rollback

  1. Ask counsel to confirm my default-on decision and the open points under Legal applicability. A different outcome is a change to the matrix with a version bump; replacing my confirmation with a counsel memo is a change to the review entry.
  2. Set NEXT_PUBLIC_ANALYTICS_REGION_POLICY=on in a preview deployment with a probe key and run the payload probe with fake x-vercel-ip-* headers for each regime.
  3. Canary under #559, watching ingestion volume.
  4. Rollback: set the flag to off and redeploy. The next page load behaves as consent-only.

What I have not verified

  • Counsel has not reviewed any row. The default-on rows rest on my confirmation.
  • The Vercel headers were not exercised on a deployment. The route reads them as documented and is tested with synthetic requests.
  • The payload probe was not extended with a region-on scenario, and no browser end-to-end test covers default-on. Both are listed under #555 and #560 above.
  • Production performance against #556 is not measured. Default-on collection raises event volume for every US and Canadian visitor, and replay cost once replay is implemented.