diff options
author | mattab <matthieu.aubry@gmail.com> | 2015-03-26 05:36:44 +0300 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2015-03-26 05:37:55 +0300 |
commit | 983e1a9e0f516e8f62a8f8c66c88a236126db7e4 (patch) | |
tree | b817887d85728e6dcec60747319eb1ffc04b6a35 /js/piwik.js | |
parent | 69105e10df9af1b8aa0f2d8fb7c7ed0a882b3d4d (diff) |
Add unit tests to piwik.js with relation to #7518
Diffstat (limited to 'js/piwik.js')
-rw-r--r-- | js/piwik.js | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/js/piwik.js b/js/piwik.js index c402ef4e22..75f9c9dbeb 100644 --- a/js/piwik.js +++ b/js/piwik.js @@ -2626,6 +2626,21 @@ if (typeof Piwik !== 'object') { } /* + * Generate a pseudo-unique ID to fingerprint this user + * 16 hexits = 64 bits + * note: this isn't a RFC4122-compliant UUID + */ + function generateRandomUuid() { + return hash( + (navigatorAlias.userAgent || '') + + (navigatorAlias.platform || '') + + JSON2.stringify(browserFeatures) + + (new Date()).getTime() + + Math.random() + ).slice(0, 16); + } + + /* * Load visitor ID cookie */ function loadVisitorIdCookie() { @@ -2636,6 +2651,7 @@ if (typeof Piwik !== 'object') { cookieValue, uuid; + // Visitor ID cookie found if (id) { cookieValue = id.split('.'); @@ -2648,20 +2664,13 @@ if (typeof Piwik !== 'object') { return cookieValue; } - // uuid - generate a pseudo-unique ID to fingerprint this user; - // note: this isn't a RFC4122-compliant UUID - if (visitorUUID.length) { + if(visitorUUID.length) { uuid = visitorUUID; } else { - uuid = hash( - (navigatorAlias.userAgent || '') + - (navigatorAlias.platform || '') + - JSON2.stringify(browserFeatures) + - now.getTime() + - Math.random() - ).slice(0, 16); // 16 hexits = 64 bits + uuid = generateRandomUuid(); } + // No visitor ID cookie, let's create a new one cookieValue = [ // new visitor '1', |