OneSignal Info

Your website can access a oneSignalInfo object that includes OneSignal data and device data for the current device via the GoNative JavaScript Bridge. As with other JavaScript Bridge functionality 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.

// oneSignalInfo contains the below
{
    oneSignalUserId: 'xxxxxxx',
    oneSignalPushToken: 'xxxxxx',
    oneSignalSubscribed: true,
    oneSignalRequiresUserPrivacyConsent: false,
    platform: 'ios',
    appId: 'io.gonative.example',
    appVersion:  '1.0.0',
    distribution: 'release',
    hardware: 'armv8',
    installationId: 'xxxx-xxxx-xxxx-xxxx',
    language: 'en',
    model: 'iPhone',
    os: 'iOS',
    osVersion: '10.3',
    timeZone: 'America/New_York'
}

Call gonative_onesignal_info() function each page load

If your website defines a function called gonative_onesignal_info() it will get called after every page load as shown below with the oneSignalInfo object.

↔️GoNative 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 gonative_onesignal_info(oneSignalInfo) {
    console.log(oneSignalInfo);
}

Trigger gonative_onesignal_info() manually

You may also run gonative_onesignal_info() manually at any time by calling gonative.onesignal.run.onesignalInfo().

↔️GoNative JavaScript Bridge

// You may also call the gonative_onesignal_info function manually
// e.g. on a single page web app
gonative.onesignal.run.onesignalInfo();

Return data via a promise

Call gonative.onesignal.onesignalInfo.then() or use await gonative.onesignal.onesignalInfo() to return a promise that will resolve with the oneSignalInfo object.

↔️GoNative JavaScript Bridge

// Or return the OneSignal Info via a promise (in async function)
var oneSignalInfo = await gonative.onesignal.onesignalInfo();

gonative.onesignal.onesignalInfo().then(function (oneSignalInfo) {
  console.log(oneSignalInfo);
});

📘

The gonative_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.


Next Steps