diff options
author | mattab <matthieu.aubry@gmail.com> | 2014-09-01 17:33:07 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2014-09-01 17:33:07 +0400 |
commit | d903c1f0be860bae5e48031baa6d0512a917dcbb (patch) | |
tree | 584f9135f4497d2ad0b8f6286594fcf657208b9d /libs | |
parent | dc48c3132757a6125203368207d71ac1fd32cc0f (diff) |
Refs #3490 User ID Tracker is now working:
- new user_id field to contain the raw user id value
- new &uid= tracker api parameter
- add userId to Live API output
- added integration test
Diffstat (limited to 'libs')
-rw-r--r-- | libs/PiwikTracker/PiwikTracker.php | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/libs/PiwikTracker/PiwikTracker.php b/libs/PiwikTracker/PiwikTracker.php index 3afc2db93a..02788cf224 100644 --- a/libs/PiwikTracker/PiwikTracker.php +++ b/libs/PiwikTracker/PiwikTracker.php @@ -196,6 +196,7 @@ class PiwikTracker $this->configReferralCookieTimeout = 15768000; // 6 months // Visitor Ids in order + $this->userId = false; $this->forcedVisitorId = false; $this->cookieVisitorId = false; $this->randomVisitorId = false; @@ -380,6 +381,7 @@ class PiwikTracker public function setNewVisitorId() { $this->randomVisitorId = substr(md5(uniqid(rand(), true)), 0, self::LENGTH_VISITOR_ID); + $this->userId = false; $this->forcedVisitorId = false; $this->cookieVisitorId = false; } @@ -975,6 +977,25 @@ class PiwikTracker $this->forcedVisitorId = $visitorId; } + + /** + * + * @param string $userId Any user ID string (eg. email address, ID, username). Must be non empty. Set to false to de-assign a user id previously set. + * @throws Exception + */ + public function setUserId($userId) + { + if($userId === '') { + throw new Exception("User ID cannot be empty."); + } + $this->userId = $userId; + } + + static public function getIdHashed($id) + { + return substr(md5( $id ), 0, 16); + } + /** * If the user initiating the request has the Piwik first party cookie, * this function will try and return the ID parsed from this first party cookie (found in $_COOKIE). @@ -989,13 +1010,21 @@ class PiwikTracker */ public function getVisitorId() { + if (!empty($this->userId)) { + return $this->getIdHashed($this->userId); + } if (!empty($this->forcedVisitorId)) { return $this->forcedVisitorId; - } else if ($this->loadVisitorIdCookie()) { + } + if ($this->loadVisitorIdCookie()) { return $this->cookieVisitorId; - } else { - return $this->randomVisitorId; } + return $this->randomVisitorId; + } + + public function getUserId() + { + return $this->userId; } /** @@ -1308,6 +1337,7 @@ class PiwikTracker // Only allowed for Super User, token_auth required, (!empty($this->ip) ? '&cip=' . $this->ip : '') . + (!empty($this->userId) ? '&uid=' . $this->userId : '') . (!empty($this->forcedVisitorId) ? '&cid=' . $this->forcedVisitorId : '&_id=' . $this->getVisitorId()) . (!empty($this->forcedDatetime) ? '&cdt=' . urlencode($this->forcedDatetime) : '') . (!empty($this->forcedNewVisit) ? '&new_visit=1' : '') . |