diff options
author | mattab <matthieu.aubry@gmail.com> | 2015-03-02 03:11:56 +0300 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2015-03-02 03:11:56 +0300 |
commit | f00b6f60b2238ded6a7e9abed7086a7a5e5a4bb1 (patch) | |
tree | 870bb82215853216645f6d7f28d9db49d2cb4839 /js | |
parent | 59f21d0bed2ebd328979219fd343ca0cb94e83e5 (diff) |
Refs #7290 Fixing wrong logic in the JS tracker: make sure Visitor ID is initialised properly in all cases
Diffstat (limited to 'js')
-rw-r--r-- | js/piwik.js | 84 |
1 files changed, 45 insertions, 39 deletions
diff --git a/js/piwik.js b/js/piwik.js index 932d2bedfa..388b88ce20 100644 --- a/js/piwik.js +++ b/js/piwik.js @@ -2163,6 +2163,9 @@ if (typeof Piwik !== 'object') { // User ID configUserId = '', + // Visitor UUID + visitorUUID = uuid || '', + // Document URL configCustomUrl, @@ -2293,10 +2296,7 @@ if (typeof Piwik !== 'object') { hash = sha1, // Domain hash value - domainHash, - - // Visitor UUID - visitorUUID = uuid; + domainHash; /* * Set cookie value @@ -2629,53 +2629,58 @@ if (typeof Piwik !== 'object') { function loadVisitorIdCookie() { var now = new Date(), nowTs = Math.round(now.getTime() / 1000), - id = getCookie(getCookieName('id')), - tmpContainer; + visitorIdCookieName = getCookieName('id'), + id = getCookie(visitorIdCookieName), + cookieValue; if (id) { - tmpContainer = id.split('.'); + cookieValue = id.split('.'); // returning visitor flag - tmpContainer.unshift('0'); + cookieValue.unshift('0'); - } else { - // uuid - generate a pseudo-unique ID to fingerprint this user; - // note: this isn't a RFC4122-compliant UUID - if (!visitorUUID) { - visitorUUID = hash( - (navigatorAlias.userAgent || '') + - (navigatorAlias.platform || '') + - JSON2.stringify(browserFeatures) + - now.getTime() + - Math.random() - ).slice(0, 16); // 16 hexits = 64 bits + if(visitorUUID.length) { + cookieValue[1] = visitorUUID; } + return cookieValue; + } - tmpContainer = [ - // new visitor - '1', + // uuid - generate a pseudo-unique ID to fingerprint this user; + // note: this isn't a RFC4122-compliant UUID + if (!visitorUUID) { + visitorUUID = hash( + (navigatorAlias.userAgent || '') + + (navigatorAlias.platform || '') + + JSON2.stringify(browserFeatures) + + now.getTime() + + Math.random() + ).slice(0, 16); // 16 hexits = 64 bits + } - // uuid - visitorUUID, + cookieValue = [ + // new visitor + '1', - // creation timestamp - seconds since Unix epoch - nowTs, + // uuid + visitorUUID, - // visitCount - 0 = no previous visit - 0, + // creation timestamp - seconds since Unix epoch + nowTs, - // current visit timestamp - nowTs, + // visitCount - 0 = no previous visit + 0, - // last visit timestamp - blank = no previous visit - '', + // current visit timestamp + nowTs, - // last ecommerce order timestamp - '' - ]; - } + // last visit timestamp - blank = no previous visit + '', + + // last ecommerce order timestamp + '' + ]; - return tmpContainer; + return cookieValue; } function getRemainingVisitorCookieTimeout() { @@ -2813,7 +2818,7 @@ if (typeof Piwik !== 'object') { } newVisitor = id[0]; - uuid = asyncTracker.getVisitorId(); + uuid = id[1]; createTs = id[2]; visitCount = id[3]; currentVisitTs = id[4]; @@ -4084,7 +4089,7 @@ if (typeof Piwik !== 'object') { * @return string Visitor ID in hexits (or null, if not yet known) */ getVisitorId: function () { - return configUserId.length ? sha1(configUserId).substr(0, 16) : (loadVisitorIdCookie())[1]; + return (loadVisitorIdCookie())[1]; }, /** @@ -4173,6 +4178,7 @@ if (typeof Piwik !== 'object') { */ setUserId: function (userId) { configUserId = userId; + visitorUUID = hash(configUserId).substr(0, 16); }, /** |