> ## Documentation Index
> Fetch the complete documentation index at: https://spotzee.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Devices and in-app notifications

> Register a browser device, fetch in-app notifications, and mark them read with the JavaScript SDK.

The JavaScript SDK can register browser device details and fetch in-app notifications for rendering inside your page.

## Register a device

`registerDevice` records a device against the current contact. The `os` field identifies the device platform. A browser can register without a push token.

```typescript theme={null}
import { Spotzee } from '@spotzee/js-sdk'

Spotzee.initialize({ apiKey: 'pk_…' })

await Spotzee.registerDevice({
  deviceId: 'browser-uuid-stored-in-localstorage',
  os: 'web',
  model: 'Chrome',
  appBuild: '2026.4.30',
  appVersion: '2.4.0',
})
```

Required fields:

| Field | Notes |
| - | - |
| `deviceId` | Stable identifier you generate and store yourself. UUID v4 is fine. |
| `os` | `web`, `ios`, `android`. The mobile SDKs set this for you; in JS you set it. |
| `model` | Free-form string. Browser name (`Chrome`, `Safari`) is a useful default. |
| `appBuild` | Free-form. Often a calendar version or commit SHA. |
| `appVersion` | Free-form. Often a semver string. |

`token` is optional. Registering a browser device without a token does not enable push delivery.

You must have called `identify`, or pass `anonymousId` / `externalId` explicitly, before `registerDevice` succeeds.

## Fetch in-app notifications

Notifications targeted at the user via campaigns or journeys land in a queue you read with `getNotifications`. The SDK does not render them; you decide when and how.

```typescript theme={null}
const { results, cursor } = await Spotzee.getNotifications()

for (const notification of results) {
  switch (notification.contentType) {
    case 'banner':
      renderBanner(notification.content)
      break
    case 'alert':
      renderAlertModal(notification.content)
      break
    case 'html':
      renderHtmlOverlay(notification.content.html)
      break
  }
}

if (cursor) {
  // More pages available. Pass cursor into the next call.
  const next = await Spotzee.getNotifications(undefined, cursor)
}
```

The three content types share `title`, `body`, and an optional `custom` map. The `alert` and `html` types also carry an `html` field with the rendered markup; `alert` adds an optional `image` URL.

## Mark a notification read

Call `markNotificationRead` once the user dismisses or acknowledges the notification. The platform stops returning it from `getNotifications` after that.

```typescript theme={null}
await Spotzee.markNotificationRead(notification.id)
```

For the `BrowserClient`, the cached `externalId` and `anonymousId` are passed automatically. For the bare `Client`, pass them as the second argument:

```typescript theme={null}
await spotzee.markNotificationRead(notification.id, {
  anonymousId: 'anon_xyz',
  externalId: 'u_42',
})
```

## Worked example: fetch on app load, mark read on dismiss

```typescript theme={null}
async function loadSpotzeeNotifications() {
  const { results } = await Spotzee.getNotifications()
  for (const n of results) {
    if (n.readAt) continue
    showInPageNotification(n, async () => {
      await Spotzee.markNotificationRead(n.id)
    })
  }
}

document.addEventListener('DOMContentLoaded', loadSpotzeeNotifications)
```

## Next steps

> [card] [Set up push providers](https://spotzee.com/docs/guides/configure-push-notifications.md)
>
> Configure APN and FCM credentials before mobile or web push can deliver.

> [card] [Typed API client](https://spotzee.com/docs/guides/sdks/javascript/typed-client.md)
>
> Server-side surface for higher-volume notification listing.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.