# Privacy and masking

> The privacy defaults of the SDKs, every option and attribute that masks more, how to keep whole areas of your app out, and how to see for yourself what is sent.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service). Status: at launch.  
Source: https://docs.sypnia.com/sdks/privacy-and-masking/

This page is for whoever is responsible for what leaves the app. It gives the names in code: options, attributes and functions. The rules behind them, in plain words, are in [Masking](https://docs.sypnia.com/privacy/masking) and [What is collected](https://docs.sypnia.com/privacy/what-is-collected). Everything here happens inside the SDK, in the person's browser or on your server, so it is the same for the open-source engine and for Sypnia Cloud.

**At the end you will have:** an app where you can state, and check, what Sypnia receives.

## The defaults you do not have to set

| Default                                                                                                                                                                              | Can it be turned off?                                                  |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------- |
| **Everything a person types is masked, always.** Text fields, text areas, dropdown choices and editable areas (`contenteditable`) are recorded as asterisks, one for each character. | No. There is no option to record typed input.                          |
| Password, card and one-time-code fields are masked.                                                                                                                                  | No.                                                                    |
| Hidden fields lose their value.                                                                                                                                                      | No.                                                                    |
| Events never carry a field's value: a click on a field reports its label or placeholder.                                                                                             | No.                                                                    |
| `url` is the path only: no origin, no query, no hash. Routes replace ids by `:id`.                                                                                                   | No.                                                                    |
| Request and response bodies, cookies and headers are never read. From a failed API call the SDK keeps a code of at most 40 characters and a message of at most 160.                  | The code and message: yes, with `capture.requestFailureDetail: false`. |
| E-mail addresses in error messages, error stacks and failure messages are replaced by `[email]`.                                                                                     | No.                                                                    |
| On the server, the message of a failed database or service call is redacted before it leaves: e-mail addresses, URLs, UUIDs, quoted values, long tokens and every run of digits.     | No.                                                                    |
| Sign-in parameters (`access_token`, `refresh_token`, `token`, `code`) are removed from links inside recordings.                                                                      | No.                                                                    |
| Frames and videos are left out of recordings. Canvas drawings are not recorded. Images are not copied.                                                                               | No.                                                                    |
| No cookies. Two random ids in `localStorage`, which identify nobody.                                                                                                                 | See `optOut` below.                                                    |

What is recorded as shown, unless you change it: **the text your pages display**, and with it the labels of what people click.

## Mask more

### One element: `data-sypnia-mask`

`checkout.html`

```html
<section data-sypnia-mask>
  <h2>Shipping address</h2>
  <p>Ada Park, 12 Elm Street, Springfield</p>
</section>
```

Inside it, letters and digits become asterisks in recordings and page snapshots, now and when the content changes later. A click inside it is reported without a label. Use it for names, addresses, amounts, messages: any text that belongs to a person.

### One element, completely: `data-sypnia-block`

`account.html`

```html
<div data-sypnia-block>
  <img src="/documents/id-card.jpg" alt="Identity card" />
</div>
```

The element is not recorded. The recording shows an empty box of the same size. Use it for images, maps, charts, embedded widgets: anything whose shape alone says too much.

### Without touching the markup: `maskSelector` and `blockSelector`

For elements you cannot put an attribute on, such as a third-party widget:

`src/main.ts`

```ts
init({
  project: 'spk_7d1f0c9e4b8a2f6d3c5e1a9b0f4d8c2e',
  maskSelector: '.customer-name, .order-total, [data-private]',
  blockSelector: '#support-chat, .map',
});
```

### Every text: `maskAllText`

`src/main.ts`

```ts
init({
  project: 'spk_7d1f0c9e4b8a2f6d3c5e1a9b0f4d8c2e',
  maskAllText: true,
});
```

Recordings then show the layout, the clicks and the movement, with every word replaced. Events change too: clicks carry no label and no context, and form failures no field name. Problems become harder to read («a button was clicked five times» instead of «Pay was clicked five times»). Choose it for an app that is sensitive throughout: health, finance, anything about children.

A project can also turn this on for every browser at once, without a deploy, with the project setting `replay.mask_all_text`. Either one is enough: the SDK masks all text when the option **or** the setting says so.

## Keep parts of the app out

| You want                            | Use                                                                                                       | Effect                                                                                                                                                                                                                                            |
| ----------------------------------- | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| No recording on some routes         | `replay: { blockedRoutes: ['/account/cards'] }` in `init`, or the project setting `replay.blocked_routes` | No replay and no page snapshot there. Recording stops on entering and resumes on leaving. Events are still sent, so problems are still found. The engine also refuses recordings of routes in the project's list, so an old tab cannot send them. |
| No recording anywhere               | `replay: false`, `snapshots: false`                                                                       | The recorder is never loaded.                                                                                                                                                                                                                     |
| Nothing at all on some routes       | `ignoreRoutes: ['/admin']`                                                                                | The SDK is inactive there: no events, no recording.                                                                                                                                                                                               |
| Nothing at all for one person       | `optOut()`                                                                                                | Remembered in that browser until `optIn()`.                                                                                                                                                                                                       |
| To change or drop an event yourself | `beforeSend`                                                                                              | See below.                                                                                                                                                                                                                                        |

A string in these lists covers the route and everything under it. Project settings are changed in the app on Sypnia Cloud, and through the [API](https://docs.sypnia.com/api/projects-keys-and-tokens) on any engine.

### Asking for consent

If your visitors must agree before analytics start, start the SDK switched off and switch it on when they agree:

`src/main.ts`

```ts
import { init } from '@sypnia/browser';

init({
  project: 'spk_7d1f0c9e4b8a2f6d3c5e1a9b0f4d8c2e',
  enabled: localStorage.getItem('analytics-consent') === 'yes',
});

export function onConsent(agreed: boolean) {
  localStorage.setItem('analytics-consent', agreed ? 'yes' : 'no');
  if (agreed) location.reload();
}
```

With `enabled: false` the SDK stores nothing in the browser and sends nothing. The reload starts it for a visitor who has just agreed.

### `beforeSend`

The last word on any event. It runs in the browser (or on your server, in the Node SDK) before the event is queued.

`src/main.ts`

```ts
init({
  project: 'spk_7d1f0c9e4b8a2f6d3c5e1a9b0f4d8c2e',
  beforeSend(event) {
    if (event.type === 'error' && event.msg.includes('order #')) {
      event.msg = event.msg.replace(/order #\w+/g, 'order #[id]');
    }
    if (event.type === 'custom' && event.name === 'internal_debug') return null;
    return event;
  },
});
```

It is not called for recording content, which is masked by the rules above and cannot be edited event by event.

## What you send on purpose

The defaults cover what the SDK collects by itself. Three functions send what **you** give them, as you give it:

- `identify()` sends the person's id and, only if you pass them, a name and an e-mail. Send the id alone if you do not want personal data in Sypnia. See [Identifying people](https://docs.sypnia.com/sdks/identifying-people).
- `track()` sends the properties you choose. Never pass what a person typed.
- `reportError()` sends the error's message. Do not build error messages out of personal data.

## See what is sent

1. Set `debug: true` in `init`. The SDK prints every event to the console before it is queued, and says why when it sends nothing.
2. Open the developer tools, tab **Network**, filter by `ingest`. Events go to `…/v1/ingest/events`, recordings to `…/v1/ingest/replay`, page snapshots to `…/v1/ingest/snapshot`. Bodies above 2,048 characters are gzipped.
3. To check masking, type something into a form, cause an error (so the session is recorded), and watch the replay: what you typed is asterisks. A recording's piece carries `mask: 1` for the default rules and `mask: 2` when all text is masked.

Every field of every event is listed in the [event schema](https://docs.sypnia.com/reference/event-schema).

## What the agent sees

The agent reads events: what was clicked, which requests failed, which error was thrown. It never reads recordings or typed input, and masked content never reaches Sypnia at all, so it cannot be sent to a model. See [Models and what is sent](https://docs.sypnia.com/agent/models-and-what-is-sent).

## Next
