# Privacy, consent and data controls

> What each SDK collects and never collects, consent in the browser, opt-out on mobile, masking, scrubbing, hashing, retention by data type, and export and deletion requests.

Source: https://apphelm.dev/docs/privacy

This page explains what AppHelm collects, what it never collects, and the controls you have: consent, masking, scrubbing rules, retention and privacy requests. You are the controller of your users' data; AppHelm gives you the switches and does the deleting.

## What the SDKs never collect

Every AppHelm SDK follows these rules, and you can't turn them off:

- **No IP addresses.** No SDK sends one, and the server doesn't store the address of a request. It reads the country for analytics and then drops the address. The one exception is ad measurement with "personalization" consent (see [IP addresses](#ip-addresses)).
- **No request headers, cookies or bodies** from server SDKs. Server middleware reads incoming headers only for `traceparent` and `sentry-trace`.
- **No emails, names or usernames from `setUser`.** Server SDKs send a hash of the user id instead. Feedback `name` and `email` are accepted for compatibility with Sentry and never sent.
- **No secrets in errors, logs and breadcrumbs.** A built-in scrubber replaces private keys, JWTs, API keys (AppHelm, OpenAI-style `sk-`, Stripe, AWS, GitHub, Slack, Google), bearer and basic credentials, `password=` style values, sensitive query parameters, credentials in URLs, emails and long hex tokens before anything is queued. Context keys named like secrets or personal data (`password`, `token`, `cookie`, `session`, `email`, `phone`, `ssn`, `card`, `iban`…) are dropped.
- **No text or values from autocapture.** A click records the element's structure and position, never its text or an input's value.
- **No password fields in replay.** Password, one-time-code and card fields are always recorded as `********`.

There is no `sendDefaultPii` option: AppHelm never sends that data, so there is nothing to turn on.

## Consent in the browser

The browser SDK collects nothing until you say the person agreed. Its consent has three parts:

| Part | Allows |
| --- | --- |
| `analytics` | Events, autocapture, pageviews, errors, tracing, logs, surveys and flag exposures; storing the anonymous id in `localStorage` |
| `replay` | Session replay. Needs `analytics` too |
| `ads` | `"measurement"` or `"personalization"`, for ad measurement. Needs `analytics` too |

The default is `{ analytics: false, replay: false }`. Call `setConsent` from your consent banner:

JavaScript (browser):
```js
apphelm.setConsent({ analytics: true, replay: true });   // the person agreed
apphelm.setConsent({ analytics: false, replay: false }); // withdrawn: the queue is cleared, replay discarded
apphelm.getConsent();                                     // { analytics, replay, ads? }
```

React:
```tsx
const apphelm = useApphelm();
<button onClick={() => apphelm?.setConsent({ analytics: true, replay: false })}>Accept analytics</button>
```

Next.js:
```tsx
"use client";
import { useApphelm } from "@sansavision/apphelm/react";

export function ConsentButtons() {
  const apphelm = useApphelm();
  return <button onClick={() => apphelm?.setConsent({ analytics: true, replay: true })}>Accept</button>;
}
```

Vue / Nuxt:
```ts
apphelm.setConsent({ analytics: true, replay: false }); // the client from createBrowserSdk
```

Svelte / SvelteKit:
```ts
apphelm.setConsent({ analytics: true, replay: false }); // the client from createBrowserSdk
```

You can also pass `consent` when you create the client, for example when your banner's answer is already stored. To be sure, `setConsent` turns replay and ads off whenever analytics is off.

- **Withdrawing analytics** clears the queue, stops autocapture and error capture, and forgets flag exposures. **Withdrawing replay** stops the recording and discards what wasn't sent.
- **Global Privacy Control:** when the browser sends GPC (`navigator.globalPrivacyControl`), consent stays off whatever `setConsent` says. GPC is read when the client is created.
- **Do Not Track** is not read.
- **`enabled: false`** sends nothing at all: no events, errors, transactions, replay, profiles, logs or feedback. Flags still load.

### What happens before consent

Nothing is stored and no event is sent. Two things still talk to AppHelm:

- **Flags.** The SDK loads feature flags at start-up, with a random anonymous id held in memory (or the id you passed). AppHelm evaluates them and stores no event. `identify` before consent sends no `$identify` event but reloads flags for the new id, and may record a hashed link between the two ids so the person keeps their flag variant.
- **Feedback.** `captureFeedback` and the feedback dialog are something the person does on purpose, so they work without analytics consent. Only `enabled: false` turns them off; GPC does not.

> **Framework cookie:** The Next.js middleware, the Nuxt plugin and the Vue helpers set an `apphelm_id` cookie (one year, `SameSite=Lax`) so server and browser use the same anonymous id. It is set before consent. Pass `cookie: false` to leave cookies alone. The browser SDK itself sets no cookies.

The browser SDK keeps the anonymous id and the identified user in `localStorage` (`apphelm.distinctId`, `apphelm.user`) and the session in `sessionStorage` (`apphelm.sessionHash`), and writes them only once analytics consent exists.

> **The `privacyMode` field:** Events carry a `privacyMode` value (`aggregate` or `consented` from the browser, `strict` from server and mobile SDKs) that records the context they were sent in. It is a label only: it doesn't change what is collected or stored. Use consent and the options on this page to control collection.

## Opt-out on mobile and servers

Mobile SDKs start collecting when the app starts, and you turn collection off with an opt-out. If your app needs consent first, start opted out and opt in from your consent screen.

iOS (Swift):
```swift
// Start opted out: ApphelmOptions(…, defaultOptedOut: true)
apphelm.optOut()   // deletes the queue; nothing is sent until optIn(); remembered across launches
apphelm.optIn()
apphelm.setReplayConsent(true) // replay needs its own consent
```

Android (Kotlin):
```kotlin
// Start opted out: ApphelmConfig(…).apply { optOut = true }
Apphelm.optOut()
Apphelm.optIn()
Apphelm.setReplayConsent(true) // replay needs its own consent
```

Flutter:
```dart
// Start opted out: ApphelmConfig(…, defaultOptIn: false)
apphelm.optOut();
apphelm.optIn();
Apphelm.instance.setReplayConsent(true); // replay needs its own consent
```

React Native / Expo:
```ts
// Start opted out: createReactNativeSdk({ …, defaultOptIn: false })
apphelm.optOut();
apphelm.optIn();
apphelm.setReplayConsent(true); // replay needs its own consent
```

On every mobile SDK, session replay records only after `setReplayConsent(true)`. Server SDKs send what your code sends; use `enabled: false` (or `enabled=False`, `Enabled = false`) to turn one off, for example in tests.

## Masking in session replay

Replay records the page's structure, not a video. These are masked or left out by default:

| What | Default |
| --- | --- |
| Input values | Masked (`maskAllInputs: true`); password, one-time-code and card fields always |
| `textarea` text | Masked while `maskAllInputs` is on |
| Editable content (`contenteditable`) | Masked, like input values, while `maskAllInputs` is on (the default); always masked in schematic mode |
| Text on the page | Recorded (`maskAllText: false`) |
| `.ph-no-capture`, `.apphelm-no-capture`, `[data-apphelm-block]` | Drawn as an empty box |
| `.ph-mask`, `.apphelm-mask`, `[data-apphelm-mask]`, `[data-apphelm-sensitive]`, `[data-private]` | Text and values masked |
| `.ph-ignore-input`, `.apphelm-ignore-input` | Typing not recorded |
| `script`, `noscript`, `template` | Never recorded |
| Canvas | Off (`recordCanvas`) |
| Console | On, with emails, JWTs, bearer tokens and long secrets masked |
| Network | Method, URL, status, timing and size; query values masked unless `recordQuery`; headers and bodies only with `recordHeaders` / `recordBody`, and auth, cookie, token and key headers always `[masked]` |
| Pages | Paused on any path with `auth`, `sign-in`, `sign-up`, `login`, `logout`, `billing`, `checkout`, `payment`, `admin` or `account/security` as a segment (`/billing`, `/settings/billing`), plus your `blockedPaths` |

JavaScript (browser):
```js
createBrowserSdk({
  key: "ahl_pub_…", workspaceId: "org_…", productId: "prd_…",
  replay: { maskAllText: true, blockSelector: ".account-number", maskSelector: ".customer-name", blockedPaths: ["/settings/billing"] },
});
```

```html
<div class="apphelm-no-capture">Never recorded</div>
<span data-apphelm-mask>Masked text</span>
```

`mode: "schematic"` records layout boxes only, with no text at all. On the server, replay console and network text is scrubbed again with the built-in rules and your scrubbing rules. `beforeSend` does not see replay. [Session replay](https://apphelm.dev/docs/session-replay) covers the rest.

Autocapture skips the paths that are, or start with, `/auth`, `/sign-in`, `/sign-up`, `/login`, `/logout`, `/billing`, `/checkout`, `/payment`, `/admin` or `/account/security` (not nested ones such as `/settings/billing`; add those in **Settings → Capture**), and elements that are password, email, phone, card, one-time-code, IBAN or SSN fields, editable content, or marked `data-apphelm-mask`, along with everything inside them.

## Scrub data yourself

### In the SDK

Every SDK has a hook that sees each event after the built-in scrubber and before it is queued. Change the event, or return null to drop it. A hook that throws drops the event.

Node.js:
```ts
const apphelm = new Apphelm({ apiKey: process.env.APPHELM_API_KEY!, workspaceId: "org_…", productId: "prd_…",
  beforeSend: (event) => (event.eventName === "internal_debug" ? null : event) }); // { eventName, properties, … }
```

JavaScript (browser):
```js
createBrowserSdk({ key: "ahl_pub_…", workspaceId: "org_…", productId: "prd_…",
  beforeSend: (event) => (event.name === "internal_debug" ? null : event) });
```

Python:
```python
def before_send(event):  # { "eventName", "properties", … }
    if event["eventName"] == "$exception":
        event["properties"]["message"] = event["properties"]["message"].replace(customer_name, "[customer]")
    return event

apphelm.init(api_key=..., workspace_id="org_…", product_id="prd_…", before_send=before_send)
```

The hook is `beforeSend` in the JavaScript, Android, iOS, Flutter and PHP SDKs, `before_send` in Python, Ruby, Rust and Elixir, and `BeforeSend` in Go and .NET. Logs have their own hook: `beforeSendLog` (`before_send_log`, `BeforeSendLog`). Each SDK's README shows the exact event shape its hook receives.

### Scrubbing rules on the server

Each product has scrubbing rules, set by owners and admins in **Errors → Settings**. They apply to errors, logs and replay console and network text before anything is stored. All are off by default:

| Rule | Replaces |
| --- | --- |
| Credit cards | Card numbers (13 to 19 digits that pass the Luhn check) with `[card]` |
| IP addresses | IPv4 and IPv6 addresses with `[ip]` |
| Terms | Up to 50 words or phrases of your own (3 to 100 characters, any case) with `[redacted]` |
| Drop tag keys | Up to 50 tag keys, removed |

Rules apply to data arriving after you save them (within about a minute); data already stored is not rewritten. The server also always applies the built-in secret and email scrubbing to error messages, stacks, breadcrumbs, tags and log lines, keeps only the origin and path of referrers, and drops event properties named like secrets or personal data from the indexed copy.

## Hashing of ids

| Id | How it is stored |
| --- | --- |
| A browser's anonymous id and your `distinct_id` | Two short hashes (32-bit each). Only the hashes are indexed. They are pseudonyms, not anonymisation |
| `setUser` / `user.id` from server SDKs | `user_hash`: the first 32 hex characters of SHA-256 of `apphelm-user:<id>` |
| Customer identifiers (email, user id) for customer profiles | SHA-256 of the workspace, namespace, type and value |
| Person ids on log lines | Hashed into the same person hashes; the id itself is not stored |
| A request's IP address, for rate limiting | HMAC-SHA256 with a server secret and the UTC day; changes every day; never stored |

The raw copy of each event kept for exports and pipelines holds what the SDK sent, including the raw `distinct_id` from server and mobile SDKs and any traits you set with `identify`. It is deleted with your plan's event retention and by privacy deletions.

Owners, admins and product managers can reveal masked personal data in the app (`?reveal=pii`). Every reveal is recorded in the audit log.

## IP addresses

AppHelm does not store your users' IP addresses. For browser events it reads the device type, browser, operating system and country from the request, stores those four values, and drops the address. Flag targeting can use the request's country, region, city and continent at evaluation time.

The one exception is ad measurement: an event the developer marked with `"personalization"` ads consent passes the address and user agent to a queued ad conversion (not to the stored event). They are cleared when the conversion is sent.

## Data retention

AppHelm deletes data on its own when it passes your plan's retention:

| Data | Free | Builder | Portfolio | Scale |
| --- | ---: | ---: | ---: | ---: |
| Events (raw copies and indexed events), heatmaps | 14 days | 30 days | 90 days | 365 days |
| Errors and issues, transactions, profiles, release sessions, LLM traces | 14 days | 30 days | 90 days | 365 days |
| Span index | 14 days | 30 days | 30 days | 30 days |
| Session replays | 14 days | 30 days | 90 days | 90 days |
| Logs | 7 days | 14 days | 30 days | 90 days |
| Customer thread entries (notes, messages) | 30 days | 180 days | 365 days | 730 days |

Feedback records and their screenshots and attachments are not removed by the customer thread period; a privacy request deletes them.

Other data has fixed periods:

| Data | Kept |
| --- | --- |
| Visit sources (attribution) of anonymous visitors | 400 days. For identified people, until their profile is deleted |
| Cron check-ins | 30 days |
| Uptime results | 90 days |
| Source maps / symbol files | 90 days / 365 days |
| Pipeline delivery log and dead letters | 14 days (no event payloads) |
| Ad click evidence | 90 days |
| Import reports of skipped rows | 7 days |

### Retention per purpose

In **Settings → Privacy & collection** you can set a shorter period for each processing purpose: product analytics, product improvement, session replay, customer success profiling, customer communication and AI processing. The shorter of the plan's period and the purpose's period applies. Before a shorter period deletes data, Settings shows how much will go and asks you to confirm. Each sweep is recorded in the audit log (`privacy.retention_applied`). Purposes can also require consent, in which case AppHelm checks the person's latest consent receipt before using their data for that purpose.

## Privacy requests

When a person asks for their data or for it to be deleted, use the privacy endpoints or the person's page in the app.

### Export

HTTP (curl):
```bash
# A customer profile (everything linked to the person)
curl -X POST https://apphelm.dev/api/v1/privacy/export \
  -H "Authorization: Bearer $APPHELM_API_KEY" -H "Content-Type: application/json" \
  --data '{"profileId":"cus_…","confirmed":true}'

# A visitor known only by a distinct id, in one product
curl -X POST https://apphelm.dev/api/v1/privacy/export \
  -H "Authorization: Bearer $APPHELM_API_KEY" -H "Content-Type: application/json" \
  --data '{"distinctId":"user-123","productId":"prd_…","confirmed":true}'
```

Needs `privacy:read`. A profile export includes the profile, its thread, its replay sessions (as a list), LLM rows and up to 1,000 log lines. `{ "email": "…", "confirmed": true }` exports status page subscriptions for that address.

### Delete

HTTP (curl):
```bash
curl -X POST https://apphelm.dev/api/v1/privacy/delete \
  -H "Authorization: Bearer $APPHELM_API_KEY" -H "Content-Type: application/json" \
  --data '{"profileId":"cus_…","confirmation":"Request 2026-118 from the person","confirmed":true}'
```

Needs `privacy:write`. `confirmation` is a note of 8 to 200 characters for the record.

- **By profile** (`profileId`): deletes the person and every profile linked to them: raw events, indexed events, replays, feedback and survey answers, attachments, identity links, log lines, LLM rows and imported events. A marker stops a later import or re-ingest from bringing them back. The key must cover every product the person is known in, or the answer is `403 workspace_scope_required`.
- **By distinct id** (`distinctId` and `productId`): for a visitor without a profile. Each call removes up to 1,000 events, 500 survey rows and 500 replays; the status is `partial` until a call finds nothing more, so repeat it.
- **By email** (`email`): removes status page subscriptions.

AppHelm reads every store again after deleting and checks samples in storage. The answer is `completed`, `in_progress` (imported events or log lines are still being removed in the background) or `failed` (HTTP 500, with what remains, so you can repeat it). It carries a signed deletion manifest: counts per store and a hash of what was removed. Fetch it later with `GET /api/v1/privacy/delete?jobId=cpj_…`.

> **Copies outside AppHelm:** A deletion can't reach data AppHelm already sent elsewhere. The answer's `externalCopies` names them: [data pipeline](https://apphelm.dev/docs/data-pipelines) destinations and exports, YouSaid threads and Yieldline conversions. Delete the person there too.

### Restrict processing

`POST /api/v1/privacy/suppress` with `{ "profileId": "cus_…", "confirmation": "…", "confirmed": true }` (scope `privacy:write`) keeps the record but stops optional processing: profile state, segments, surveys, interventions and pipeline deliveries skip the person. Send `"suppressed": false` to lift it. Live events from a suppressed person are still received; delete the person to stop that.

Owners and admins can do all three from a customer's page in the app (**Export data**, **Delete person**, **Suppress processing**). Requests made through the app or the API are recorded in the audit log.

## Pause collection

An owner or admin with access to every product can pause collection for the whole workspace in Settings. While it is paused, every ingest route refuses new data with `409`, and nothing already stored changes. Resuming is recorded in the audit log like pausing.

## Where data is processed

AppHelm runs on Cloudflare (Workers, D1, R2 and Queues). A workspace's region setting is a preference, not a storage guarantee: EU-only storage or processing is not offered today. The current list of subprocessors is at [apphelm.dev/subprocessors](https://apphelm.dev/subprocessors), and the data processing agreement at [apphelm.dev/dpa](https://apphelm.dev/dpa).

## Best practices

- **Ask before you collect in the browser.** Wire your consent banner to `setConsent`, and keep the default (nothing before consent).
- **Never put personal data in event names, URLs or ids.** Use an internal user id for `identify`, not an email.
- **Mark sensitive elements** with `data-apphelm-mask` or `.apphelm-no-capture` before turning on replay, and review a few recordings.
- **Turn on scrubbing rules** for card numbers and IP addresses if your error messages or logs might contain them.
- **Set purpose retention** to what your privacy notice promises, and add a privacy notice link per purpose so survey widgets can show it.
- **Handle deletions with the API** and keep the manifest as your record.

## Troubleshooting

| Symptom | Likely cause | What to do |
| --- | --- | --- |
| No events from the browser | Analytics consent hasn't been given, or the browser sends GPC | Call `setConsent({ analytics: true })` after the person agrees; GPC users stay opted out by design |
| No replays | Replay consent is missing, or the page is on a paused path | Call `setConsent({ analytics: true, replay: true })`; check `blockedPaths` |
| Text you need is masked in replay | It is an input, or matches a mask selector | Inputs are masked by default; unmask only what is safe |
| A secret still reached AppHelm | It doesn't look like a known secret | Add it to the product's scrubbing terms, or remove it in `beforeSend` |
| `403 workspace_scope_required` on delete | The person is known in products the key doesn't cover | Use a key that covers every product, or delete from the app as an owner |
| `403 product_scope_denied` on a distinct-id export or delete | The `productId` is outside the key's products, or is the demo product | Use a key for that product |
| A distinct-id deletion says `partial` | More data than one call removes | Repeat the call until the status is `completed` |
| A deletion is `in_progress` | Imported events or log lines are being removed in the background | Fetch the job with `GET /api/v1/privacy/delete?jobId=…` later |
| A deleted person's data is still at a destination | AppHelm can't delete copies it already sent | Use the `externalCopies` list to delete it there |
