Cordova Unique Device ID plugin

I want to use this plugin:
https://www.npmjs.com/package/cordova-plugin-uniquedeviceid

It seems to be very simple, but I can’t make it work.

// Get UUID
window.plugins.uniqueDeviceID.get(success, fail);

Success callback function:

function success(uuid)
{
    $$('span#id').text(uuid); //To show the ID in the app
    console.log(uuid);
};

If someone had use it, and know how to make it works, thanks in advance.

I have used this:

Example:

const uuidv4 = require('uuid/v4');
 var uuid = uuidv4();

Thanks i’m gonna try.

The npm uuid package’s uuid isn’t tied to the device. You can find some better options in this package: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-device/

Thank you. I’m going to try it, it seems that it suits my needs better. Since it has to be the same even if the app is uninstalled.

I use Phonegap Build, i don’t know exactly how to call the plugin in the XML file.
I put this <plugin name="cordova-plugin-device" spec="~2.0.3" source="npm" /> (URL, VERSION, SOURCE) it’s correct.
How can i check if it’s ok.?

Try with this code but doesn’t work.
document.addEventListener("deviceready", onDeviceReady, false);

function onDeviceReady() {
    var deviceID = device.uuid;
    var element = document.getElementById('textuuid');
        element.innerHTML = 'Device Model: '    + deviceID + '<br />';
}

Since that plugin is 5 years old, you might try this more current fork:

That version doesn’t seem to support the requirement “Remains the same after app uninstall” according to its docs.

thats right, i need to remains the same after uninstall.

I make it work, and uninstall the app and reinstall, and has the same UUID.

Plugin I use

For Phonegap Build.

config.xml
<plugin name="cordova-plugin-device" />

app.js
var deviceID = device.uuid;
console.log(deviceID);
$$("span#textuuid").append(deviceID); // if you wont to show somewhere in the app

Thats all.
Thanks to all for your help.

1 Like