# Anonymous visitors

> Observe public pages (a landing, a sign-up form, a pricing calculator) without knowing who the visitor is and without leaving an identifier on their device.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://telemetry.docs.sypnia.com/sdks/anonymous-visitors/

For agents: Read this to observe public pages with @sypnia/telemetry 0.3.0. Browser init({ anonymousRoutes: ['/demo', '/signup'] , anonymous: { replay?: false, hideClickText?: false } }); Node init({ anonymousRoutes }) or withSypnia({ server: { anonymousRoutes } }). On an anonymous route: no identify (calls are kept in memory and only apply on other routes), events carry anon: true and person/account null, no device id, a per-tab session id in sessionStorage that dies with the tab (no cookie, no localStorage), every typed value excluded as always, custom event props and click/error text scrubbed of e-mails, phone and document numbers, replay and page snapshots off unless anonymous.replay is true (then every text is masked). anonymousRoutes are observed even when allowRoutes does not list them. Leaving an anonymous route for a signed-in one in the same tab continues the session; identity applies from that moment on, never to earlier events. Server: requests on anonymous routes are traced with sypnia.anonymous = true; identify() is ignored in them. Sessions list filter: anonymous=true|false.

Some pages of your app have visitors you do not know and should not track: the landing, a sign-up form, a price calculator, a page a customer's family opens from a link. You still want to know whether they work: whether the form fails, where people give up, which button nobody can click.

**Anonymous mode** observes those pages without identity. It is a list of routes, `anonymousRoutes`, available from version **0.3.0** of `@sypnia/telemetry`.

> **In plain words**
>
> On the pages you mark, Sypnia sees what happens on the page but never who is there. It leaves nothing on the visitor's device that lasts beyond the open tab.

## Turn it on

In the browser, list the public routes in `init`:

`src/sypnia.ts`

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

init({
  project: 'spk_…',
  // Signed-in areas: observed as before, with identify().
  allowRoutes: ['/app', '/settings'],
  // Public pages: observed anonymously.
  anonymousRoutes: ['/', '/pricing', '/signup', /^\/invite\/[^/]+$/],
});
```

A route in `anonymousRoutes` is observed even when `allowRoutes` does not list it. `ignoreRoutes` still wins over both.

On the server, give the same list so the requests those pages make are traced the same way:

`Node`

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

init({ anonymousRoutes: ['/', '/pricing', '/signup', '/api/public'] });
```

`next.config.ts (Next.js)`

```ts
export default withSypnia(nextConfig, {
  server: { anonymousRoutes: ['/', '/pricing', '/signup', '/api/public'] },
});
```

## What changes on an anonymous route

|                                                                        | Signed-in routes                                              | Anonymous routes                                                                                                                                                     |
| ---------------------------------------------------------------------- | ------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `identify()`                                                           | Attaches the person and account to every event                | Ignored. A call made there is kept in memory and only applies once the visitor reaches a route that is not anonymous.                                                |
| `person`, `account` on events                                          | The identified ones                                           | Always `null`. Events carry `anon: true`.                                                                                                                            |
| Device id (`did`)                                                      | 32 hex in `localStorage`, `sypnia:device`                     | Not created, not read, not sent.                                                                                                                                     |
| Session id                                                             | `localStorage`, shared by every tab, 30 minutes of inactivity | `sessionStorage` (`sypnia:anon`), this tab only. Gone when the tab closes, or after 30 minutes of inactivity. No cookie.                                             |
| Typed values                                                           | Never captured                                                | Never captured                                                                                                                                                       |
| Custom event properties (`track`)                                      | As you send them                                              | Strings scrubbed: e-mail addresses become `[email]`, runs of 6 or more digits (phones, document numbers) become `[number]`. Numbers of 9 or more digits are dropped. |
| Click labels and context                                               | The visible text, unless `maskAllText`                        | Scrubbed like properties. With `anonymous.hideClickText`, no label and no context at all.                                                                            |
| Error messages                                                         | E-mails replaced                                              | E-mails and digit runs replaced                                                                                                                                      |
| Replays and page snapshots                                             | As configured                                                 | Off. With `anonymous.replay: true`, on, with every text of the page masked.                                                                                          |
| Page views, clicks, rage and dead clicks, errors, failed calls, vitals | Captured                                                      | Captured                                                                                                                                                             |

`anonymous` options:

| Option          | Default | What it does                                                                                                                                                                       |
| --------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `replay`        | `false` | Records replays and page snapshots on anonymous routes. Every text is masked there, whatever `maskAllText` says. The session's replay decision is asked without person or account. |
| `hideClickText` | `false` | Sends no label and no context with clicks and form errors on anonymous routes: only the element's position and its selector.                                                       |

## From an anonymous page to a signed-in one

A visitor who signs up on `/signup` and lands on `/app` in the same tab keeps one session: the trace of the sign-up continues into the app. Identity starts when your app calls `identify()` on the signed-in route.

- The events sent before keep `person: null`. Nothing is rewritten after the fact.
- The session in the list shows the person from that moment, because a session shows the latest identified person it saw. The session also shows that it had anonymous pages.

The other way round, a signed-in person who opens an anonymous route gets a separate anonymous session there, so a public page is never tied to someone's account by its session.

## Privacy and consent

This mode is designed to stay outside what needs a consent banner in most cases, but whether you need consent is your decision and depends on your law. What it does and does not do:

- **Nothing that lasts.** No cookie, nothing in `localStorage`. The only stored value is a random session id in `sessionStorage`, deleted when the tab closes. It cannot recognise a returning visitor.
- **No identity.** No person, no account, no device id. The engine stores the events with `person` empty.
- **What a request still carries.** The engine receives the visitor's IP address with every request, as any server does. Sypnia uses it for rate limits only and does not store it with the events.
- **What you send is yours.** A custom property is scrubbed of the common patterns above, but a name or an address written into a property is not recognised. Do not put personal data in `track()` properties.

Under the GDPR, an anonymous session of this kind is often treated as data that does not identify a person. Combined with other data it might be, so check with whoever handles privacy for you before turning on `anonymous.replay`.

## In the engine and the console

- Each event keeps `anon: true`. Server spans of anonymous routes carry the attribute `sypnia.anonymous = true`, and their `url.path` is the route (`/invite/:id`), never the path with its ids or tokens (0.3.1).
- A session that had anonymous pages has `anonymous: true` in `GET /v1/sessions` and in the session's page.
- `GET /v1/sessions?anonymous=true` lists only those sessions; `anonymous=false`, only sessions without anonymous pages.
- The console's session list has the same filter.

An engine without this field still stores the events of anonymous routes and shows their sessions, only without the filter: an event field it does not know is kept, never refused.
