how can I get a unique device ID in javascript?

If installed as an app on a mobile device or smart TV, you’ll probably have a enough access to get a hold of something unique. I wouldn’t necessarily go for a Mac address, but different devices will have different unique identifiers you can grab (even just a phone number would be a pretty good bet for a mobile phone).

Browsers, which are the most restricted environment you listed, are a different story.

Short answer, no.

Longer answer, no, but kinda.

There is no way to get any kind of identifier that is truly unique and unchangeable from the client. This means no MAC address, serial number, IMSI, or any of those other things.

You’d have to turn to an approach which advertisers frequently use to track you across the web.

Basically, you scoop up all the information you can access about a user. These things may include user agent string, IP address, OS, and the like. Basically, things that are sent in an HTTP request and/or via JavaScript client-side. By combining these values together, you can create something that’s going to be reasonably unique fingerprint, though not guaranteed and will greatly vary by physical environment that users access it by.

For example, if I’m using my computer at home, and I’m all alone, and I have a fixed IP address, then getting my IP address alone will probably point to just me. If I’m in a college library or an office environment though, and pretty much every other computer all uses the same external IP (quite common a lot of times), and all of them are roughly the same amount of up-to-date, then a lot of people will show up all as the same user even if you mix a bunch of different data points together.

Depending on your use-case, it may be “good enough” (which is generally what advertisers go with), but if it you are using it for any kind of auto-access to security, don’t do it. It’s never going to be anywhere near secure enough for that. If you want to do something like that, at the very least mix it with a cookie and/or session specific values to reduce the risks.

Leave a Comment