0

Problem:

I have a JavaScript advertising unit which generates a UUID in the client browser using a JavaScript function. The UUID is used to link together different sorts of activity from the unit. For example: initial load, load complete, someone clicked it, among others. The unit is deployed on multiple websites. I am observing a high occurrence of duplication in the UUIDs generated, of the order of 1% (total volume is of the order of 300, 000-400, 000 hits per day).

Investigation:

To investigate this I have:

  • tested the JavaScript function by generating 10, 000, 0000 UUIDs and found no duplicates UUIDs generated (I even made the seed of time a constant).
  • load tested the unit locally 10, 000 times and found no duplicate UUIDs generated.
  • looked into any correlation between a duplicate UUID occurring and
    1. user agent;
    2. website (host);
    3. ip address;
    4. time of day; and
    5. style of unit.
      I have found strong correlation with website (host) - given a duplicate UUID it is generally only found within one website (although there are exceptions to this), BUT they are spread over different IP addresses. Also, no duplicate UUID straddles a one day period - that is if I query my activity for a known duplicate and order by time the smallest and largest time is always within a one day period between 12 a.m. and 12 p.m.

I was initially thinking this is a caching issue but I don't know how this can be the case when the duplicates are coming from totally different IP addresses. The unit works by having a small script tag on the website which then downloads the relevent JavaScript and CSS files for the unit.

NB - For speed of display I cannot wait for a server round trip to generate the UUID server side because this would delay loading the unit (I.e. initial load generates the UUID, load complete must use the same UUID - if UUID was generated server side load complete would have to wait for initial loads response)

Question:

Does anyone have any ideas about what could be causing this duplication?

Reference:

JavaScript UUID code:

generateUUID : function() {
    var d = new Date().getTime();
    var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = (d + Math.random()*16)%16 | 0;
        d = Math.floor(d/16);
        return (c=='x' ? r : (r&0x7|0x8)).toString(16);
    });
    return uuid;
}

(reference: Create GUID / UUID in JavaScript?)

Community
  • 1
  • 1
Stuart
  • 3,226
  • 5
  • 24
  • 28
  • very similar question here: http://stackoverflow.com/questions/6906916/collisions-when-generating-uuids-in-javascript – Stuart Oct 09 '14 at 08:49
  • It is worth looking at the comments as well as the answers on that alternate question as it is a goldmine on this topic. There are several suggested solutions also. – Fenton Oct 15 '14 at 06:55

0 Answers0