Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@gmail.com>2014-09-10 18:42:08 +0400
committerThomas Steur <thomas.steur@gmail.com>2014-09-10 18:42:08 +0400
commit77abe4062a9fc71524a3a79c92c77f1cfced5eba (patch)
treeb960a6c19074cf2fa54956420dba5a6a17f9b124 /core/Tracker/Request.php
parentdf65e0dd10f12e11990665971e5f7e019168fd39 (diff)
parent25545fdc55a1decd13548c1f3f6479789956e56c (diff)
Merge remote-tracking branch 'origin/master' into 4996_content_tracking
Conflicts: core/Metrics.php js/piwik.js piwik.js tests/javascript/index.php
Diffstat (limited to 'core/Tracker/Request.php')
-rw-r--r--core/Tracker/Request.php64
1 files changed, 49 insertions, 15 deletions
diff --git a/core/Tracker/Request.php b/core/Tracker/Request.php
index 6a7f96b0b9..659c5fac6a 100644
--- a/core/Tracker/Request.php
+++ b/core/Tracker/Request.php
@@ -29,8 +29,6 @@ class Request
*/
protected $params;
- protected $forcedVisitorId = false;
-
protected $isAuthenticated = null;
protected $tokenAuth;
@@ -277,6 +275,7 @@ class Request
'cip' => array(false, 'string'),
'cdt' => array(false, 'string'),
'cid' => array(false, 'string'),
+ 'uid' => array(false, 'string'),
// Actions / pages
'cs' => array(false, 'string'),
@@ -442,21 +441,37 @@ class Request
}
/**
- * Is the request for a known VisitorId, based on 1st party, 3rd party (optional) cookies or Tracking API forced Visitor ID
+ * Returns the ID from the request in this order:
+ * return from a given User ID,
+ * or from a Tracking API forced Visitor ID,
+ * or from a Visitor ID from 3rd party (optional) cookies,
+ * or from a given Visitor Id from 1st party?
+ *
* @throws Exception
*/
public function getVisitorId()
{
$found = false;
+ // If User ID is set it takes precedence
+ $userId = $this->getForcedUserId();
+ if(strlen($userId) > 0) {
+ $userIdHashed = $this->getUserIdHashed($userId);
+ $idVisitor = $this->truncateIdAsVisitorId($userIdHashed);
+ Common::printDebug("Request will be recorded for this user_id = " . $userId . " (idvisitor = $idVisitor)");
+ $found = true;
+ }
+
// Was a Visitor ID "forced" (@see Tracking API setVisitorId()) for this request?
- $idVisitor = $this->getForcedVisitorId();
- if (!empty($idVisitor)) {
- if (strlen($idVisitor) != Tracker::LENGTH_HEX_ID_STRING) {
- throw new Exception("Visitor ID (cid) $idVisitor must be " . Tracker::LENGTH_HEX_ID_STRING . " characters long");
+ if (!$found) {
+ $idVisitor = $this->getForcedVisitorId();
+ if (!empty($idVisitor)) {
+ if (strlen($idVisitor) != Tracker::LENGTH_HEX_ID_STRING) {
+ throw new Exception("Visitor ID (cid) $idVisitor must be " . Tracker::LENGTH_HEX_ID_STRING . " characters long");
+ }
+ Common::printDebug("Request will be recorded for this idvisitor = " . $idVisitor);
+ $found = true;
}
- Common::printDebug("Request will be recorded for this idvisitor = " . $idVisitor);
- $found = true;
}
// - If set to use 3rd party cookies for Visit ID, read the cookie
@@ -473,6 +488,7 @@ class Request
}
}
}
+
// If a third party cookie was not found, we default to the first party cookie
if (!$found) {
$idVisitor = Common::getRequestVar('_id', '', 'string', $this->params);
@@ -480,7 +496,7 @@ class Request
}
if ($found) {
- $truncated = substr($idVisitor, 0, Tracker::LENGTH_HEX_ID_STRING);
+ $truncated = $this->truncateIdAsVisitorId($idVisitor);
$binVisitorId = @Common::hex2bin($truncated);
if (!empty($binVisitorId)) {
return $binVisitorId;
@@ -517,16 +533,14 @@ class Request
}
}
- public function setForcedVisitorId($visitorId)
+ public function getForcedUserId()
{
- if (!empty($visitorId)) {
- $this->forcedVisitorId = $visitorId;
- }
+ return $this->getParam('uid');
}
public function getForcedVisitorId()
{
- return $this->forcedVisitorId;
+ return $this->getParam('cid');
}
public function getPlugins()
@@ -556,4 +570,24 @@ class Request
}
return false;
}
+
+ /**
+ * @param $idVisitor
+ * @return string
+ */
+ private function truncateIdAsVisitorId($idVisitor)
+ {
+ return substr($idVisitor, 0, Tracker::LENGTH_HEX_ID_STRING);
+ }
+
+ /**
+ * Matches implementation of PiwikTracker::getUserIdHashed
+ *
+ * @param $userId
+ * @return string
+ */
+ private function getUserIdHashed($userId)
+ {
+ return sha1($userId);
+ }
}