getDeviceId
This function returns a unique identifier (GUID) for the current device. The ID persists across browser sessions and is stored in the device's local storage. This is useful for device-specific functionality, analytics, or tracking usage patterns.
Syntax
app.getDeviceId()
Parameters
This function takes no parameters.
Return Value
Returns a String containing a GUID (globally unique identifier) that uniquely identifies the current device.
Examples
Example 1: Basic usage to get the device ID:
// Get the unique device identifier
const deviceId = app.getDeviceId();
console.log("Device ID: " + deviceId);
Example 2: Store device-specific settings:
// Get the device ID
const deviceId = app.getDeviceId();
// Store device-specific settings in database
app.sqlWrite("SaveDeviceSettings", {
deviceId: deviceId,
displayMode: "dark",
fontSize: "large",
notificationsEnabled: true
});
Example 3: Check if a device is authorized:
// Get the device ID
const deviceId = app.getDeviceId();
// Check if this device is authorized
const authorizedDevices = app.sqlRead("GetAuthorizedDevices");
const isAuthorized = authorizedDevices.some(device => device.deviceId === deviceId);
if (!isAuthorized) {
app.showErrorMessage("Unauthorized Device", "This device is not authorized to access this application.");
}
Example 4: Track first-time usage:
// Get the device ID
const deviceId = app.getDeviceId();
// Check if this is the first time this device has used the app
const deviceHistory = app.sqlRead("GetDeviceUsageHistory", { deviceId: deviceId });
if (!deviceHistory.length) {
// First time user on this device
app.sqlWrite("LogDeviceFirstUse", { deviceId: deviceId });
// Show welcome message for new device
app.showMessage("Welcome", "Welcome to our application! Let us show you around.");
}
Related Functions
getBrowserToken()
- For getting a browser-specific identifier (changes if browser storage is cleared)getCustomSetting()
- For retrieving custom settings that might be device-specificsqlRead()
- For retrieving data from the database using the device IDsqlWrite()
- For storing device-specific data in the database
Notes
- The device ID is stored in local storage and persists even when cookies are cleared
- If local storage is cleared, a new device ID will be generated
- This ID is device-specific, not user-specific
- For user-specific identification, use authentication functions
- Use this function with caution and consider privacy implications when tracking device IDs