Device Info
Call each page load
If your website defines a function called median_device_info()
, it will get called after every page load as shown below with an object that contains information about your native app and the user's device.
Trigger manually
You may also run median_device_info()
manually at any time by calling median.run.deviceInfo()
.
Return via a promise
Call median.deviceInfo.then()
or use await median.deviceInfo()
to return a promise that will resolve with the data.
Usage
You may POST the device data to your server via AJAX, or anything else that's required using JavaScript.
Examples
// 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_device_info(deviceInfo) {
console.log(deviceInfo);
}
// You may also call the median_device_info function manually, e.g. on a single page web app
median.run.deviceInfo();
// Or return the OneSignal Info via a promise (in async function)
var deviceInfo = await median.deviceInfo();
median.deviceInfo().then(function (deviceInfo) {
console.log(deviceInfo);
});
// deviceInfo will look like
{
platform: 'ios',
appId: 'io.median.example',
appVersion: '1.0.0',
appBuild: '1.0.0', // will be appVersionCode (number) on Android
carrierNames: ['AT&T'], // array of all connected mobile carriers
distribution: 'release',
hardware: 'armv8',
installationId: 'xxxx-xxxx-xxxx-xxxx',
apnsToken: '<xxxxxxxx xxxxxxxx xxxxxxxx ... >', // only on iOS
language: 'en',
model: 'iPhone',
os: 'iOS',
osVersion: '10.3',
timeZone: 'America/New_York',
isFirstLaunch: false // first time the app is launched
}
Median JS Bridge NPM Library Helper Method
When using the Median JS Bridge NPM Library you may call the helper function getPlatform()
which will return web
, ios
or android
accordingly.
The
median_device_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.
On Android the parameter
carrierNames
requires the permissionREAD_PHONE_STATE
Developer Demo
Display our demo page in your app to test during development https://median.dev/device-info/
Updated 15 days ago