# Event payload spec

> Every event type the SDK sends, with its fields and the server's constraints, and the device context sent with each batch in its two tiers.

Every SDK call that records something becomes an event in the device's queue. Events travel to Herald inside a batch, through `POST /api/v1/sdk/batch` ([SDK REST endpoints](/docs/reference/rest-endpoints#post-api-v1-sdk-batch)). This page lists every event type and the device context, with the rules the server enforces.

Lengths count UTF-16 code units. The SDKs check these rules on the device and drop a call that breaks them. If an event still breaks a rule, Herald rejects only that event, keeps the rest of the batch and lists it in the response's `rejected` (see [Rejected events](/docs/reference/error-codes#rejected-events)). An event can be up to 32 KB as JSON.

## Fields on every event

| Field | Type | Rules |
|---|---|---|
| `id` | string | 1 to 128 characters. A UUID the SDK creates. Herald stores each ID once per connection. |
| `type` | string | One of the types below |
| `timestamp` | string | ISO 8601 date-time with offset; when the call was made, by the device's clock. Herald stores it corrected for the device's clock (see [Clock correction](/docs/concepts/batching-and-offline#clock-correction)) and rejects events more than 30 days old |
| `sessionId` | string | Optional, 1 to 64 characters. The session start time in epoch milliseconds. |

## Event types

### session_start

| Field | Type | Rules |
|---|---|---|
| `properties.session_index` | integer | Optional (SDK 0.6.0 and later), 1 or more. Sessions started on this install, counting from 1. |
| `properties.previous_session_id` | string or null | Optional (SDK 0.6.0 and later), 1 to 64 characters. The session before this one on the install; null for the first. After an update from an earlier SDK, the first new session has `session_index` 1 but can name the last session of the old SDK. |

Queued when a session starts. A wrong type rejects the event (`invalid_field`); other keys in `properties` are dropped. SDKs before 0.6.0 send no `properties`. See [Sessions](/docs/concepts/sessions).

### session_end

| Field | Type | Rules |
|---|---|---|
| `durationSeconds` | number | 0 or more; last activity minus start |

Queued when the next session starts, at sign-out and at a user switch. Its timestamp is the session's last activity.

### identify

| Field | Type | Rules |
|---|---|---|
| `userId` | string | 1 to 200 characters |
| `traits` | object | Optional. Attribute map (see below). |

From `identify`. Traits are merged into the profile of a verified user.

### track

| Field | Type | Rules |
|---|---|---|
| `name` | string | 1 to 255 characters |
| `properties` | object | Optional. Keys up to 255 characters; values any JSON. |
| `schemaVersion` | string | Optional. SDK 0.6.0 and later. The [event schema](/docs/concepts/event-schemas) version to check the event against, such as `1-0-0`; without it (or null), the latest version. Ignored, whatever its value, when the event name has no schema; when it has one, a value that isn't one of its versions rejects the event (`unknown_schema_version`). The SDKs send only well-formed versions. |

From `track`, and the SDK's lifecycle events below.

#### Lifecycle events

SDK 0.6.0 and later send these `track` events on their own. Each property is checked for its type when present; a wrong type rejects the event (`invalid_field`). They are sent in minimal data collection too, since they carry no personal data. They show as system events on the Events page, and you can pick them as goals and in segment rules like any event name.

| Name | Fires | Properties |
|---|---|---|
| `$app_installed` | The first launch of this install. Doesn't start a session. | `version`, `build` (strings) |
| `$app_updated` | The first launch with a different app version or build than the last launch. Doesn't start a session. | `version`, `build`, `previous_version`, `previous_build` (strings) |
| `$app_opened` | The first foreground of the app's process: a cold start, or a process the system started in the background that the person then opens | `from_push` (boolean): the launch came from a notification tap the SDK saw first (see below) |
| `$app_foreground` | Every move from the background to the foreground, and a launch's first foreground. Not after a system alert, Control Center, Face ID or a call banner (iOS), nor a rotation, dark mode change or resize (Android). | None |
| `$app_background` | Every move to the background. Never starts or ends a session. | None |
| `$deep_link_opened` | A deep link goes through the SDK: a push tap's link, or `openDeepLink` (iOS) / `openUrl` (Android), which the default message and card views use | `scheme`, `host`, `path`, `query` (strings), `source` (`push` or `link`) |

`trackLifecycleEvents` (default on) turns off the first five, `trackDeepLinks` (default on) the last. `$deep_link_opened` never has the fragment or `;parameters`, and has the query only with `trackDeepLinkQuery` on. A URL without a host (`mailto:`, `tel:`, `sms:`, `data:`) sends `scheme` and `source` only, so an address or number never reaches the event log. In minimal data collection it has `scheme`, `host` and `source` only. The path of a web link is sent, so keep tokens out of link paths.

On iOS, `from_push` is reliable only in apps that forward the notification response (`handleNotificationResponse`) before the app becomes active. Scene-based apps, including SwiftUI apps, usually get the response after activation, so they usually report `false` even for a launch from a push. On Android it is reliable when `handleNotificationIntent` runs in the activity's `onCreate`.

`$app_opened`, `$app_foreground` and the app's other events count as app activity (last active, active days, send-time checks); `$app_installed`, `$app_updated`, `$app_background` and `$external_push` don't: iOS and Android can launch an app in the background, and a push your app reports isn't the person using it. Server events from your backend (other than `$external_push`) do update last active, active days and DAU/MAU, but never the send-time checks, which count only activity from the device. An app updated from an SDK before 0.6.0 doesn't send `$app_updated` on its first 0.6.0 launch; it stores the version then.

`$external_push` is a reserved `track` name for a push your app sent itself. Its properties are `category` (`transactional`, `marketing` or `other`; default `other`; any other value rejects the event with `invalid_field`), an optional `message_id` (1 to 200 characters) and an optional `source` (1 to 100 characters). Other properties are dropped, so a title or body is never stored. Events with the same `message_id` for the same user are stored once, whether the SDK or your backend sends them. The SDKs send it with `trackExternalPush`. See [Pushes your app sends](/docs/push-notifications/pushes-your-app-sends).

#### Geofence events

SDK 0.7.0 and later (not released yet) send these `track` events from the `HeraldGeofence` (iOS) and `herald-geofence` (Android) modules, only after the app calls `enableGeofences()`. Each property is checked for its type when present; a wrong type rejects the event (`invalid_field`). They don't count as app activity: crossings happen in the background.

| Name | Fires | Properties |
|---|---|---|
| `$geofence_enter` | The device entered one of the app's geofences. At most once per geofence every 5 minutes. | `geofence_id`, `geofence_name` (strings) |
| `$geofence_exit` | The device left one. At most once per geofence every 5 minutes. | `geofence_id`, `geofence_name` (strings) |

No coordinates are sent. See [Geofences](/docs/concepts/geofences).

### screen

Same fields as `track`. From `screen`.

### purchase

| Field | Type | Rules |
|---|---|---|
| `productId` | string | 1 to 255 characters |
| `price` | number | Any number; the SDKs require it to be finite |
| `currency` | string | Exactly 3 characters; the SDKs send it upper-cased |
| `quantity` | integer | 1 or more |
| `properties` | object | Optional. Same rules as `track`. |

From `trackPurchase`.

### attributes

| Field | Type | Rules |
|---|---|---|
| `attributes` | object | Attribute map (see below) |

From `setAttribute`, `setAttributes`, `setEmail`, `setPhone` and `setLocation`.

**Attribute map.** Keys 1 to 255 characters. Values: string, number, boolean, null, or an array of strings. Reserved keys:

| Key | Stored as |
|---|---|
| `$email` | The user's email contact. An invalid address is skipped; the rest of the event is kept. |
| `$phone` | The user's SMS contact, E.164. An invalid number is skipped. |
| `$latitude`, `$longitude` | The device's location (numbers, -90 to 90 and -180 to 180). Not written to the user profile. |
| `computed_…` | Reserved for [computed attributes](/docs/concepts/computed-attributes). An event with such a key is rejected with `invalid_field`. |

Every other key is merged into the verified user's profile: a key you send replaces the stored value, and keys you do not send stay.

### subscription

| Field | Type | Rules |
|---|---|---|
| `channel` | string | `push`, `email`, `sms` |
| `state` | string | `subscribed`, `unsubscribed`, `opted_in` |

From `setSubscription` and `requestPushAuthorization`. `unsubscribed` suppresses the channel: for push, this device's tokens; for email and SMS, the user's addresses. The other states lift an earlier unsubscribe, never a bounce or complaint. With no matching contact, the event changes nothing.

### push_token

| Field | Type | Rules |
|---|---|---|
| `platform` | string | `apns`, `fcm`, or `apns_live_activity` (the iOS Live Activity push-to-start token) |
| `token` | string | 1 to 4,096 characters. APNs tokens are lowercase hex. |
| `environment` | string | Optional, APNs only: `production` or `sandbox` |
| `bundleId` | string | Optional, 1 to 255 characters |

From `setPushToken`, and sent again after `identify`, a user switch and `reset()`. Within a batch, a `push_token` always comes before a push `subscription`. A new token replaces this device's previous one.

### interaction

| Field | Type | Rules |
|---|---|---|
| `messageId` | string | 1 to 200 characters |
| `kind` | string | `content_card`, `in_app`, `push` |
| `action` | string | `impression`, `click`, `dismiss`, `open`, `button`, `video_play`, `video_complete` |
| `buttonId` | string | 1 to 200 characters; required when `action` is `button` |
| `decisionId` | string or null | Optional, 1 to 200 characters |

| Kind | Actions the SDK sends | From |
|---|---|---|
| `content_card` | `impression`, `click`, `dismiss`, `video_play`, `video_complete` | The default feed, or `logImpression`, `logClick`, `logDismissal`, `logVideoPlay`, `logVideoComplete` |
| `in_app` | `impression`, `click`, `button`, `dismiss`, `video_play`, `video_complete` | The presenter, or `logVideoPlay`, `logVideoComplete` (iOS) and `InAppMessageActions` or `InAppMessageCallbacks` (Android) |
| `push` | `open`, `button`, `dismiss` (iOS, with a custom dismiss action) | `handleNotificationResponse` (iOS), `handleNotificationIntent` (Android) |

For a push, `messageId` is the push's `herald_message_id`, else its decision ID. A push button tap sends `open`, then `button`.

`video_play` and `video_complete` (SDK 0.6.0) are sent once per play of a video in a card or an in-app message. They are stored as events and are not credited to a decision: they change none of the viewed, clicked or dismissed states.

How Herald credits a decision: `impression` counts as delivered; `click` and `button` count as a click; `dismiss` as a dismissal; a push `open` as an open. Credit goes only to a decision that belongs to the verified user.

## Context

Each batch carries a `context` object with the device's current data. Tier 2 keys are absent, not null, in minimal mode.

### Tier 1: always sent

| Field | Type | Max length | Example |
|---|---|---|---|
| `app.name` | string | 255 | `Lumen` |
| `app.version` | string | 64 | `4.2.0` |
| `app.build` | string | 64 | `812` |
| `app.namespace` | string | 255 | `com.lumen.app` (bundle ID or package name) |
| `os.name` | string | 1 to 64 | `iOS`, `Android` |
| `os.version` | string | 64 | `18.1` |
| `region` | string or null | 8 | `US`, from the device locale |

The batch also carries `deviceId`, `sdk.name` and `sdk.version` at the top level.

### Tier 2: standard mode only

| Field | Type | Max length | Values |
|---|---|---|---|
| `device.manufacturer` | string | 128 | `Apple`, or the Android build manufacturer |
| `device.model` | string | 128 | Model identifier, such as `iPhone16,1` |
| `device.type` | string | 32 | iOS: `phone`, `tablet`, `tv`, `desktop`, `car`, `headset`. Android: `phone`, `tablet`. |
| `screen.width`, `screen.height` | number | | Points on iOS, dp on Android |
| `screen.density` | number | | Scale factor |
| `locale` | string | 64 | BCP 47 tag, such as `en-US` |
| `language` | string | 32 | `en` |
| `timezone` | string | 64 | IANA zone, such as `America/Chicago` |
| `network.type` | string | 32 | `wifi`, `cellular`, `ethernet`, `other`, `none` |
| `push.authorization` | string | 32 | iOS: `authorized`, `denied`, `provisional`, `ephemeral`, `not_determined`. Android: `authorized`, `denied`, `not_determined` (Android 13 and later, before the permission is requested). |

The SDKs cut over-long strings to these maxima. A field the device cannot read is left out.

### Consent: while set

SDK 0.6.0+. Sent in both modes from the app's `setConsent` call until `clearConsent`. An invalid or null value is left out and the rest of the batch is kept; Herald stores it as a rejected event with reason `invalid_consent` (see [Rejected events](/docs/reference/error-codes#rejected-events)).

| Field | Type | Max length | Values |
|---|---|---|---|
| `consent.basis` | string | | `consent`, `contract`, `legal_obligation`, `vital_interests`, `public_task`, `legitimate_interests` |
| `consent.documentId` | string, optional | 100 | Your policy or terms, such as `privacy-policy` |
| `consent.documentVersion` | string, optional | 100 | Such as `2026-11` |
| `consent.recordedAt` | ISO 8601 time | | When the app called `setConsent` |

Herald keeps it on the device record and, for a verified user, as the reserved attribute `$consent` (the latest one sent). Apps can't set `$consent` through attributes.

Never sent: advertising identifiers, IDFV, Android ID, carrier, IP address, and location (unless your app calls `setLocation`).

## Example

```json
{
  "sdk": { "name": "herald-android", "version": "0.4.0" },
  "deviceId": "0f5e8c1a-7d1b-4b9e-8a52-3c6d2e1f4a90",
  "userId": "u_123",
  "sentAt": "2026-11-09T14:00:05Z",
  "dropped": 0,
  "context": {
    "app": { "name": "Lumen", "version": "4.2.0", "build": "812", "namespace": "com.lumen.app" },
    "os": { "name": "Android", "version": "15" },
    "region": "US",
    "device": { "manufacturer": "Google", "model": "Pixel 8", "type": "phone" },
    "screen": { "width": 412, "height": 915, "density": 2.625 },
    "locale": "en-US", "language": "en", "timezone": "America/Chicago",
    "network": { "type": "wifi" }, "push": { "authorization": "authorized" }
  },
  "events": [
    { "id": "e1", "type": "session_start", "timestamp": "2026-11-09T13:58:00Z", "sessionId": "1762696680000",
      "properties": { "session_index": 4, "previous_session_id": "1762610280000" } },
    { "id": "e2", "type": "push_token", "timestamp": "2026-11-09T13:58:01Z", "sessionId": "1762696680000",
      "platform": "fcm", "token": "fcm-token", "bundleId": "com.lumen.app" },
    { "id": "e3", "type": "subscription", "timestamp": "2026-11-09T13:58:01Z", "sessionId": "1762696680000",
      "channel": "push", "state": "opted_in" },
    { "id": "e4", "type": "track", "timestamp": "2026-11-09T13:59:58Z", "sessionId": "1762696680000",
      "name": "workout_completed", "properties": { "minutes": 32 } },
    { "id": "e5", "type": "interaction", "timestamp": "2026-11-09T14:00:02Z", "sessionId": "1762696680000",
      "messageId": "msg_1", "kind": "content_card", "action": "click", "decisionId": "dec_1" }
  ]
}
```

## Related

- [SDK REST endpoints](/docs/reference/rest-endpoints)
- [Events and attributes](/docs/concepts/events-and-attributes)
- [Device data collected](/docs/concepts/device-data)
- [Limits](/docs/reference/limits)
