---
title: Apps (through your backend)
description: Send events from iOS, Android, desktop or game apps through your own API, with app, OS and device context.
order: 9
---
# Apps (through your backend)

Apps send their events to **your own API**, which forwards them to Erised with the secret key. No Erised key ships inside the app, your backend decides exactly what leaves, and the same code serves iOS, Android, desktop and games.

```text
app ──(your session token)──▶ your API ──(sk_live_…)──▶ POST https://app.erised.run/v1/batch
```

## In the app

- Queue events locally (name, properties, the time they happened, and a client id per event) and send them to your API in small batches, for example every few seconds or when the app goes to the background.
- Before the person signs in, the simplest is to **hold the events** and send them once they do, with their user id. If your API accepts events before sign-in, give the install a random id instead (a UUID kept in the Keychain or app storage, never a hardware id), send it as the anonymous id, and pass the same id in the identify at login so those events join the person.

## In your API

1. **Authenticate** the request with your own session, and take the user id from the session, never from the request body. Requests before sign-in (if you accept them) carry only the install id.
2. **Allow-list** event names and properties. Drop anything else: free text, tokens and personal data never leave.
3. **Forward** in batches to `POST /v1/batch` with the secret key:

```js
// Node, server side only. ERISED_SECRET_KEY comes from your secret store.
const batch = events.map((e) => ({
  type: 'track',
  name: e.name,                                 // allow-listed, snake_case
  ...(session ? { userId: session.userId } : {}),   // from your session
  ...(e.installId ? { anonymousId: e.installId } : {}), // before sign-in
  messageId: `app:${session?.userId ?? e.installId}:${e.clientId}`, // a retry is stored once
  timestamp: e.occurredAt,
  properties: e.properties,                     // allow-listed
  context: {
    app: { name: 'YourApp', version: req.headers['x-app-version'], build: req.headers['x-app-build'] },
    os: { name: 'iOS', version: req.headers['x-os-version'] },
    device: { type: 'mobile', model: req.headers['x-device-model'] },
    ip: clientIp(req), // used for the country, then dropped by Erised
  },
}));

await fetch('https://app.erised.run/v1/batch', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.ERISED_SECRET_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({ batch }),
  signal: AbortSignal.timeout(5000),
});
```

Keep each request to 100 events per request at most. Retry on `429` (after `Retry-After`) and `5xx`; drop the batch on any other `4xx`.

4. **Identify** at signup and at every login with `POST /v1/identify`, the user id, `properties.email` and `properties.traits`. When the app sent an install id, pass it as `anonymousId`: the events sent before login join the person's profile.
5. **Server events** (account created, payment, deletion) go straight from your API with a `messageId` built from your record, for example `account_created:<user id>`.

## The app context

| Field | Example | Shown as |
| --- | --- | --- |
| `context.app.version`, `context.app.build` | `1.4.4`, `212` | **App versions** on the person's profile |
| `context.os.name` | `iOS`, `Android`, `macOS`, `Windows` | **Operating systems** (common spellings are normalised) |
| `context.device.type` | `mobile`, `tablet`, `desktop`, `console` | **Devices**. When absent, Erised infers it from the OS (an iPad model is a tablet). |
| `context.ip` | the user's public IP | **Countries**. The IP is used for the lookup and never stored. |
| `sessionId` (top level) | a UUID per app launch | The **sessions** count |

The device model and OS version may be sent; Erised does not store them in its derived data.

## Screens

There is no separate screen event type: track a screen as `<screen>_viewed`, for example `map_viewed`, so it can be a funnel step like any event.

## Errors from apps

Apps report errors the same way as events: the app sends them to your API, and your API forwards them with the secret key, in the same `POST /v1/batch` as events or one at a time to `POST /v1/error`.

```js
// In your API, next to the events above.
const errorEvent = {
  type: 'error',
  name: e.name ?? 'Error',                        // TypeError, NetworkError…
  ...(session ? { userId: session.userId } : { anonymousId: e.installId }),
  messageId: `app-error:${session?.userId ?? e.installId}:${e.clientId}`,
  timestamp: e.occurredAt,
  properties: {
    message: e.message,
    stack: e.stack,                               // the raw JS stack, Hermes included
    handled: e.handled,                           // false for a crash
    level: e.fatal ? 'fatal' : 'error',
    release: `ios@${appVersion}+${appBuild}`,     // the build that crashed
    environment: 'production',
    tags: { screen: e.screen },                   // allow-listed, flat strings
  },
  context: {
    app: { name: 'YourApp', version: appVersion, build: appBuild },
    os: { name: 'iOS', version: osVersion },
  },
};
```

- **`release`**: one value per shipped build, such as `ios@1.4.4+212` or `android@1.4.4+212`. "Resolve as of a release" then means "fixed from that build"; an older build that still crashes does not reopen the issue as a regression.
- **`environment`**: `production` for store builds, `development` for dev builds (hide it in **Settings → Errors**), and `integration-test` for a test you send while wiring this up (always hidden by default).
- **Grouping in release builds.** Erised reads Hermes stacks (`at fn (address at main.jsbundle:1:83421)`), but a release build has one bundle file for the whole app, React included, and minified function names. When every frame is like that, Erised groups by the error type and the message instead of the frames. If your messages carry ids or names that vary, or if different crashes share a message, send your own `fingerprint`, for example the error type, the message with its variable parts removed, and the screen: `` fingerprint: `${e.name}|${normalised}|${e.screen}` ``.
- **Location data.** If errors can carry coordinates or map cell ids, mask them in the app, and turn on **Location data** in **Settings → Errors**, which removes latitude, longitude pairs and H3 cell ids before storage.
- Check a payload before sending it with the MCP tool `validate_event`: it shows the issue the error would form.
