OneSignal Info
Your website can access a oneSignalInfo
object that includes OneSignal data and device data for the current device via the Median JavaScript Bridge. As with other JavaScript Bridge functionalities, there are alternate ways to interact with the OneSignal integration. You may send the oneSignalInfo
data to your server via AJAX, or anything else that's required on your website/web application using JavaScript.
{
oneSignalId: 'xxxxxxx',
externalId: 'xxxxxxx',
subscription: {
id: 'xxxxxxx',
token: 'xxxxxxx',
optedIn: 'xxxxxxx'
},
requiresUserPrivacyConsent: true,
platform: 'ios',
appId: 'co.median.example',
appVersion: '1.0.0',
distribution: 'release',
hardware: 'armv8',
language: 'en',
model: 'iPhone',
os: 'iOS',
osVersion: '10.3',
timeZone: 'America/New_York',
legacy: false
}
// oneSignalInfo contains the below
{
oneSignalUserId: 'xxxxxxx',
oneSignalPushToken: 'xxxxxx',
oneSignalSubscribed: true,
oneSignalRequiresUserPrivacyConsent: false,
platform: 'ios',
appId: 'co.median.example',
appVersion: '1.0.0',
distribution: 'release',
hardware: 'armv8',
language: 'en',
model: 'iPhone',
os: 'iOS',
osVersion: '10.3',
timeZone: 'America/New_York',
legacy: false
}
Call median_onesignal_info()
function each page load
median_onesignal_info()
function each page loadIf your website defines a function called median_onesignal_info()
, it will get called after every page load as shown below with the oneSignalInfo
object.
↔️Median JavaScript Bridge
// You define this function on your page, but do not actually call it // If present on a page it will be called by the app when the page is loaded function median_onesignal_info(oneSignalInfo) { console.log(oneSignalInfo); }
Trigger median_onesignal_info()
manually
median_onesignal_info()
manuallyYou may also invoke median_onesignal_info()
manually at any time by calling median.onesginal.info()
↔️Median JavaScript Bridge
// You may also call the median_onesignal_info function manually // e.g. on a single page web app median.onesignal.info({"callback": "median_onesignal_info"});
Return data via a promise
Call median.onesignal.onesignalInfo.then()
or use await median.onesignal.onesignalInfo()
to return a promise that will resolve with the oneSignalInfo
object.
↔️Median JavaScript Bridge
// Or return the OneSignal Info via a promise (in async function) var oneSignalInfo = await median.onesignal.onesignalInfo(); median.onesignal.info().then(function (oneSignalInfo) { console.log(oneSignalInfo); });
The
median_onesignal_info()
function is called by the native app when the page is loaded within the app. This function must be available at the time of page load and cannot be loaded asynchronously or in a deferred manner. If this is not possible, use the promise-based methods.
Updated 6 months ago