Device
Access the device / app's information of the customer.
Description
The device variable exposes information about the current device running the app. Use it to tailor layouts or logic based on OS type, screen size, app version and other device characteristics. If a user switches devices or reinstalls the app, they receive a new device identifier.
Properties
| Property | Type | Scope | Description | Example |
|---|---|---|---|---|
device.id | String | Global | Unique Id associated with each device | D40B48A7-0889-4E76-894 |
device.locale | String | Global | The language / region which is set as default in the device | en_US |
device.os | Enum | Global | The operating system of the device | ios |
device.osVersion | String | Global | The version of the Operating system of the device | 14.2.3 |
device.windowHeight | Float | Global | The height of the screen. | 600 |
device.windowWidth | Float | Global | The width of the screen. | 400 |
device.vajroVersion | String | Global | The version of Superfans app installed on the device | 2.14.6 |
device.appStoreVersion | String | Global | The latest version of the app from app store / play store | 1.0.0 |
device.pushNotificationStatus | Enum | Global | The permission the end user has granted for push on the device. | allowed | not_allowed |
Example usage
const device_details = VajroSDK.variables.device;
// Example: adjust layout for larger screens
if (device_details.windowWidth < 600) {
// Render a screen specific layout
}
// Display the OS and version
console.log(`Running on ${device.os} ${device.osVersion}`);
// Check push notification permission
if (device.pushNotificationStatus === 'not_allowed') {
// Prompt the user to enable notifications
}Best Practices
- Responsive design: Use windowWidth and windowHeight to adapt layouts to different screen sizes.
- Handle enum values: For os and pushNotificationStatus, always handle all supported values (e.g. ios vs. android, allowed vs. not_allowed)
- Do not treat device.id as a persistent user ID: It changes if the app is reinstalled or installed on another device.
- Read‑only fields: Device properties are read‑only; attempting to modify them has no effect.
Caveats
- device.id is specific to the physical device and installation; new installations generate new IDs
- On very old OS versions, some fields might not be populated; always check that a field exists before using it.
- Push notification status (allowed or not_allowed) reflects the user’s choice and may change if they update permissions in their system settings.
Updated about 1 month ago