Skip to main content
The JavaScript SDK covers two related surfaces: device registration (so you can target the user with push) and in-app notifications (so you can render messages inside the page).

Register a device

registerDevice records a device against the current user. The os field tells Spotzee what kind of surface this is. For browser tracking you can register without a push token; for web push you pass the subscription token.
Required fields: token is optional. Without it, the call still records the device against the user (useful for cross-device tracking and per-device journey logic) but won’t deliver push to it. You must have called identify, or pass anonymousId / externalId explicitly, before registerDevice succeeds.

Web push

The SDK does not implement the Web Push API itself. You wire up the standard browser primitives, ask the user for permission, subscribe to a service worker, and pass the resulting subscription endpoint into registerDevice as token. The full flow:
  1. Register a service worker that handles push events.
  2. Call Notification.requestPermission() from a user gesture.
  3. Subscribe via serviceWorkerRegistration.pushManager.subscribe({ userVisibleOnly: true, applicationServerKey: '<your VAPID public key>' }).
  4. Send the subscription’s endpoint, keys, and auth to your backend.
  5. Pass that subscription identifier as token into Spotzee.registerDevice({ os: 'web', token, … }).
Configure the corresponding push provider under SettingsIntegrations before tokens you register can deliver. Read Set up push notifications for the provider side.

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.
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.
For the BrowserClient, the cached externalId and anonymousId are passed automatically. For the bare Client, pass them as the second argument:

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

Next steps

Set up push providers

Configure APN and FCM credentials before mobile or web push can deliver.

Typed API client

Server-side surface for higher-volume notification listing.