Upsight logo Back to top

Converting UIDs

Overview


Upsight Analytics is only able to accept 64-bit integers as UIDs for mobile applications and 63 bit integers for social applications. If you are using our product on platforms that either use non-integer UIDs, or UIDs which are greater than 64-bits/63-bit, a hashing method to truncate the UIDs to an appropriate sized integer must be performed.

Go through the following steps to truncate UIDs.

Step 1


Hash the UIDs.

For this example, the MD5 hash method will be used. This method will produce a 128-bit (16-byte) hash value.

Example: After using the MD5 hash method,

00000011196323425873

becomes

12e79eebe3ed807324639efcdebe8638

Step 2


Truncate the hashed number to 15 digits. Integers in ActionScript or JavaScript can only be as large as 253 so if you are using the ActionScript or JavaScript SDK, you will need to truncate to 13 digits.

Shorten the MD5 hash by keeping the first 15 digits and cutting off the rest.

Example:

12e79eebe3ed807324639efcdebe8638

Truncated to 15 digits:

12e79eebe3ed807

Truncated to 13 digits:

12e79eebe3ed8

Step 3


Convert that truncated 15 digit number back to a decimal (Base 10).

Example: Back to a decimal,

12e79eebe3ed807

becomes

85139509267585031

Review


The UID goes through the following process in the above examples:

  • Long UID
  • MD5 Hash
  • Truncate to 15 Digits
  • Convert to Decimal
  • Good UID

Example


The following is an example of creating a good UID in PHP.

<?php
    function convertUID($userID) {
        return number_format(hexdec(substr(md5($userID), 0,15)), 0, "", "");
    }
?>