Device Fingerprinting

Below are the APIs for assigning, getting and removing a fingerprint on user browser. The language used is Javascript. I'll be explaining on how to use the APIs and what are the expected output. You can use them according to your needs.

The are 5 API for this library namely:-

  • getLocation()
  • getUUID()
  • storeUUIDAndCountry(uuid, country, countryCode)
  • getStoredUUIDAndCountry()
  • removeStoredUUIDAndCountry()

Initializing

To use the library, make sure you import and load the library to your site.

							
<script src="https://api.mobileuuid.io/functions.js"></script>
							
						

Usage

getLocation()

When you use this API, user's browser will prompt asking permission from them to get their location. If the user decline it, you will receive error. If user accepts it, the browser then detect user location and will give us their coordinates. With their coordinates, we will reverse it to get their location address. We use third party API, Nomatim OpenStreetMap to reverse the geocode. After the process is done, our API will return data in JSON format. To use the API, we is needed to call it asyncronously as the API will return a Promise. You can get the data by using Promise way or Async/Await way.

Promise way:-

							
getLocation().then(function(address) {
  console.log(address);
});
							
            

Async/Await way:-

                
async () => {
  var address = await getLocation();
  console.log(address);
}
                
              

Example output:-

                  
// JSON data output:-

{
  police: "Kuala Lumpur Traffic Police Station",
  road: "Jalan Tun H S Lee",
  neighbourhood: "Bukit Petaling",
  suburb: "Bukit Bintang",
  state: "Kuala Lumpur",
  postcode: "50000",
  country: "Malaysia",
  country_code: "my",
}
                  
                
getUUID()

This API will generate UUID Type 4 which is randomly generated ID. You will need this for the storeUUIDAndCountry(uuid, country, countryCode) function. The algorithm uses Javascript Crypto API instead of Javascript Math API to prevent the risk of collision.

Example to use:-

              
var uuid = getUUID();
console.log(uuid);
              
            

Expected output:-

              
// UUID string:-

"83abc155-09cd-4cb5-ae30-a25df8ecc64d"
              
            
storeUUIDAndCountry(uuid, country, countryCode)

Here is where the fingerprinting implemented. With the location and UUID that we acquired, we can now store it in user browser to identify a user and identify them later. We will need to pass the user's country name, generated UUID and optionally user's country code. The output will return objects of all stored data exists from the Javascript Storage API.

Example 1 (Promise way):-

                
getLocation().then(function(address) {
  var uuid = getUUID();

  var stored = storeUUIDAndCountry(uuid, address.country, address.country_code);
  console.log(stored);
  console.log(stored.uuid);
  console.log(stored.country);
  console.log(stored.country_code);
});
                
              

Example 2 (Async/Await way):-

              
async () => {
  var address = await getLocation();
  var uuid = getUUID();

  var stored = storeUUIDAndCountry(uuid, address.country, address.country_code);
  console.log(stored);
  console.log(stored.uuid);
  console.log(stored.country);
  console.log(stored.country_code);
};


              
            

Output:-

              
StorageĀ {uuid: "83abc155-09cd-4cb5-ae30-a25df8ecc64d", country_code: "my", country: "Malaysia", length: 3}
"83abc155-09cd-4cb5-ae30-a25df8ecc64d"
"Malaysia"
"my"
              
            
getStoredUUIDAndCountry()

We can retrieve the stored data with this API. The output will return objects of all stored data exists from the Javascript Storage API. Alternatively, you can use Javascript's window.localStorage, as our API uses the same method.

To use:-

              
var get = getStoredUUIDAndCountry();
console.log(get);
              
            

Expected output:-

              
// Javascript Storage API data object:-

StorageĀ {uuid: "83abc155-09cd-4cb5-ae30-a25df8ecc64d", country_code: "my", country: "Malaysia", length: 3}
              
            
removeStoredUUIDAndCountry()

If you want to remove the data that you have just injected, you can use this API. It will remove the UUID, country and country code that exists in the user storage. The output will return objects of all stored data exists from the Javascript Storage API which ofcourse will be empty. Alternatively, you can use Javascript's window.localStorage.clear(), but it will remove all stored data even the unrelated ones.

To use:-

              
var remove = removeStoredUUIDAndCountry();
console.log(remove);
              
            

Expected output:-

              
// Javascript Storage API data object:-

StorageĀ {length: 0}
              
			

User Agent:

Is Android Emulator SDK?:

Is Android Emulator Build?:

Has Accelerometer?:

Has Gyroscope?:

Is Real Android Device?: