How the OneSignal user model works
OneSignal assigns every user a unique internal ID (oneSignalId) the first time they launch your app. This ID is tied to the user, not the device, meaning if the same user installs your app on a second phone and you associate them with the same identifier, OneSignal links both devices to a single user record.
This is the foundation of targeted notifications. Without associating your own user identifiers, OneSignal can only target users by device, which breaks down the moment a user reinstalls the app or signs in on a new device.
View diagram
Signing users in and out
Associate a user with your own identifier, using their email address, account ID, or any unique string, by callinglogin() after they authenticate in your app:
oneSignalId and maintain the association across reinstalls and devices. You can then target that user by their externalId from your server.
When a user signs out of your app, call logout() to disassociate them from their OneSignal user record:
logout(), notifications sent to that externalId won’t reach the device until login() is called again. This prevents users from receiving each other’s notifications on a shared device.
When to call
login()Call it as soon as your user authenticates: on your sign-in confirmation page or immediately after a successful session check. Don’t wait for a user action.Retrieving user and device identifiers
Your website can access aoneSignalInfo object through the Median JavaScript Bridge. This object contains the identifiers and subscription status you need for backend targeting, analytics, and consent management.
Data structure (SDK v5+)
Retrieval method 1: Automatic callback
Define a function namedmedian_onesignal_info on your page. The app calls it automatically after the page loads, passing the oneSignalInfo object as the argument:
Retrieval method 2: Manual invocation
Callmedian.onesignal.info() directly to trigger the callback on demand. Useful for single-page applications where the callback function may not be present at initial load:
Retrieval method 3: Promise-based
If you can’t guarantee the callback function will be defined at page load, use the promise approach:Save identifiers to your backend
If you send notifications from your own server or need to correlate OneSignal data with your user records,- Save the identifiers after sign-in.
- Call
median.onesignal.info()ormedian.onesignal.onesignalInfo()(after the user has signed in). - POST the result to your backend and store it keyed by your app’s user ID.
updateUserRecord and set userId from your auth system. Your backend can then use oneSignalExternalId (or oneSignalUserId) when calling the OneSignal API to target that user; subscription.id is useful for targeting a specific device. The same pattern works with native fetch() or any HTTP client.
Developer DemoThe results of the
median_onesignal_info() callback and other OneSignal functions can be tested on our demo site. Open this page within your app to view and test: https://median.dev/onesignal/When to use each identifier
For most apps,
externalId is the right choice for personalized notifications since it maps naturally to your existing user database without any additional device tracking.
Segmenting with data tags
Data tags are name-value string pairs you assign to users. They let you group users into segments for targeted broadcasts, “users who prefer sports content,” “users on a free plan,” and “users who haven’t opened the app in 30 days.” You can set tags from the OneSignal dashboard or API; for subscription management on the device, you can use either a native UI driven by a hosted JSON file, or your own web UI in the WebView plus the JavaScript Bridge (setTags, getTags, deleteTags). Use whichever fits your UX. Many apps combine both (for example, a full preferences page using one method and in-context toggles using the other).
Method 1: Native UI
OneSignal provides a native subscription preference screen, so no custom HTML is required. You host a JSON file that defines sections and tag identifiers, point Median at that URL, and callshowTagsUI() when you want to present it.
- Create a JSON file defining the tag categories and items you want to offer. Host it at a publicly accessible URL. See the example
tags.jsonfor the JSON structure Median expects. - In App Studio, go to Native Plugins > OneSignal and set the Data Tags Native UI JSON URL to your hosted file.
- Trigger the UI from anywhere in your app:

Subscription management native UI
Method 2: Web UI and JavaScript
Build subscription controls in your web layer, meaning anything you render in the WebView: a full-screen list of topics (similar in spirit to the native UI), toggles beside related content, or mixed flows. Wire buttons and switches to the Median JavaScript Bridge so tag changes sync to OneSignal on the device. OneSignal concepts: For how data tags work in OneSignal generally (dashboard, segments). The snippets below are the Median JavaScript Bridge reference forsetTags, getTags, and deleteTags (promise and callback patterns).
Set tags
{ success: true } (and getTags includes a tags object). They support both promise-based and callback patterns.
A web UI can present the same structure as the native screen, including a full list of subscription categories a user can toggle on or off:

Example web UI: full subscription list

Example web UI: subscribing in context