Device Indexing

Get the User's Current Device ID to Identify Sessions

The Despia Device ID SDK enables your application to retrieve a unique device identifier for tracking and security purposes without collecting personal data. This provides crucial security measures for your backend, including user validation during free trials, prevention of subscription sharing, multiple account creation monitoring, and detection of unusual login behavior.

Quick Start

1. Enable Device ID Retrieval

Enable the device ID retrieval by calling the Despia SDK.

window.despia = "get-uuid://"

2. Access the Device ID

Access the unique device identifier that is stored in the uuid variable.

console.log(uuid)
// Send to your backend with auth token

3. Implement Backend Validation

Use the device ID for backend validation of users, subscriptions, and login patterns.

// Example of sending the device ID to your backend
sendToBackend({
    deviceId: deviceId, // Despia variable
    userId: currentUser.id, // Sample data
    authToken: userToken // Sample data
})

How It Works

The Device ID SDK generates a unique identifier for each device that accesses your application. This identifier remains consistent across sessions for the same device, allowing you to track and validate user behavior without relying on personal data.

The device ID is stored locally on the user's device and can be accessed through the SDK to be sent to your backend for validation purposes. This enables you to implement various security measures to protect your application from misuse.

Implementation Examples

Here are practical examples of how to implement the Device ID SDK for different use cases:

// Basic implementation to get device ID
window.despia = "get-uuid://";

const deviceId = uuid;
console.log("Device ID:", deviceId);

// EXAMPLES FOR NO-CODE/LOW-CODE TOOLS
        
// ---------- WEWEB ----------     
// WEWEB example using wwWorkflow to handle device ID
// 1. Create a Native WeWeb Global Workflow and return the variable:         
return deviceId     
// 2. This will now return the value via the code-block     
// 3. Process the code-block response accordingly, such as setting a variable or calling an API.

// ---------- WIZED ---------- 
// WIZED example using Wized's JS API
// Store the detected data in a Wized variable
v.deviceIdentifier = deviceId;

// OPTIONAL - Create a request (API Call) that will process the data
const result = await Wized.requests.execute('VALIDATE_DEVICE');
console.log(result); // Or set result as variable for display
        
// ---------- NORDCRAFT / TODDLE ---------- 
// For Nordcraft / Toddle - trigger an event with the data
// Create a custom event handler in your project settings
ctx.triggerActionEvent("onDeviceIdentified", {
    deviceId: deviceId,
    timestamp: new Date().getTime()
});

Data Structure

The device ID is a simple string containing a unique identifier for the device.

// Example of a device ID
"550e8400-e29b-41d4-a716-446655440000"

Best Practices

Implementation

  • Access the uuid variable directly after initializing the SDK

  • Store the device ID securely on your backend

  • Never expose device IDs in client-side code or URLs

  • Implement proper error handling if the device ID cannot be retrieved

Security

  • Link device IDs to user accounts for tracking purposes

  • Monitor login patterns across different devices

  • Implement rate limiting for device IDs that attempt multiple account creations

  • Create a blacklist for device IDs associated with fraudulent activities

User Experience

  • Inform users about device tracking in your privacy policy

  • Only track device IDs for legitimate security purposes

  • Provide users with the ability to remove their device from their account

Complete Implementation Example

Here's a complete implementation example showing how to integrate the Device ID SDK for subscription validation:

// Retrieve the device ID
window.despia = "get-uuid://";

// Simple function to link user ID with device ID
function linkUserToDevice(userId) {
    const deviceId = uuid;
    
    // Send to your backend
    fetch('https://api.yourapp.com/link-device', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'Authorization': `Bearer ${userAuthToken}`
        },
        body: JSON.stringify({
            userId: userId,
            deviceId: deviceId
        })
    });
}

// Call when user logs in
linkUserToDevice(currentUser.id);

Troubleshooting

Common Issues

Device ID is Undefined

  • Ensure you're accessing the uuid variable after initializing the SDK

  • Check that the Despia SDK is properly initialized

  • Verify that the SDK is correctly loaded in your application

Multiple Device IDs for Same User

  • This could indicate account sharing or device switching

  • Implement a system to associate multiple devices with a single user account

  • Set limits on the number of devices allowed per account

Device ID Not Persisting

  • Ensure you are testing on a real device or native simulator

  • Implement a fallback identification method if needed

Need Help?

For additional support or questions, please contact our support team at support@despia.com

Updated on