diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2020-06-26 16:17:54 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-26 16:17:54 +0300 |
commit | de5ae85e7a11f7bbd962256c890a32188c40d000 (patch) | |
tree | 2a5f303c83b6e80369d3ba77b2d9fea797c598d9 /core/Tracker | |
parent | b12946909ff323ea2f7e7af04e4435d2dd503023 (diff) |
Track seconds instead of days for "days since" dimensions (#15774)
* Modify dimensions and add tests.
* unfinished debugging commit
* changes to fix test, remove tracker code, add update code
* fix some tests
* fix migration issue
* fixing some tests
* fix some bugs, update some expected test files, remove _idvc from some tests
* start replacing _ects
* Finish seconds since last ecommerce order change.
* fix couple issues
* fix a couple tests
* fix some more tests
* fixing a couple more tests
* apply review feedback
* unfinished commit
* add back dimensions =
* fixing tests & removing some code
* fix some bugs + tests and remove debugging code
* fixing some tests and issues
* Some debugging code for the tracker in case of exceptions.
* debug and fix another issue when tracking visits in the past
* fix test
* update JS and fix several tests
* Fixing more tests.
* Add missing files.
* update expected test files
* Add some unit tests.
* update more expected files
* update more test files
* update more test files
* update changelog and remove _ects query param
* apply review feedback
* fix merge issue
* clearer code
* fix migration issue
* update expected files
* update expected files again
* updating tests
* fix test
* rebuilt piwik.js
* unify previous visitor properties / original visit row approach
* fixing some tests
* Add new column version entries into the option table.
* try undoing 1.5 update change
* apply review feedback
* remove more unused cookie values
* rebuilt piwik.js
* Fix test count.
* update test files
* rebuilt piwik.js
* removel log analytics submodule update
* update submodule
* update some expected screenshots
* Fix versions in omnifixture since we were probably adding to the beta update after it changed.
* update screenshots
Diffstat (limited to 'core/Tracker')
-rw-r--r-- | core/Tracker/Request.php | 72 | ||||
-rw-r--r-- | core/Tracker/Visit.php | 11 | ||||
-rw-r--r-- | core/Tracker/Visit/VisitProperties.php | 5 | ||||
-rw-r--r-- | core/Tracker/Visitor.php | 29 | ||||
-rw-r--r-- | core/Tracker/VisitorRecognizer.php | 12 |
5 files changed, 44 insertions, 85 deletions
diff --git a/core/Tracker/Request.php b/core/Tracker/Request.php index b40a283e41..591ccc0971 100644 --- a/core/Tracker/Request.php +++ b/core/Tracker/Request.php @@ -237,74 +237,6 @@ class Request } /** - * @return float|int - */ - public function getDaysSinceFirstVisit() - { - $cookieFirstVisitTimestamp = $this->getParam('_idts'); - - if (!$this->isTimestampValid($cookieFirstVisitTimestamp)) { - $cookieFirstVisitTimestamp = $this->getCurrentTimestamp(); - } - - $daysSinceFirstVisit = floor(($this->getCurrentTimestamp() - $cookieFirstVisitTimestamp) / 86400); - - if ($daysSinceFirstVisit < 0) { - $daysSinceFirstVisit = 0; - } - - return $daysSinceFirstVisit; - } - - /** - * @return bool|float|int - */ - public function getDaysSinceLastOrder() - { - $daysSinceLastOrder = false; - $lastOrderTimestamp = $this->getParam('_ects'); - - if ($this->isTimestampValid($lastOrderTimestamp)) { - $daysSinceLastOrder = round(($this->getCurrentTimestamp() - $lastOrderTimestamp) / 86400, $precision = 0); - if ($daysSinceLastOrder < 0) { - $daysSinceLastOrder = 0; - } - } - - return $daysSinceLastOrder; - } - - /** - * @return float|int - */ - public function getDaysSinceLastVisit() - { - $daysSinceLastVisit = 0; - $lastVisitTimestamp = $this->getParam('_viewts'); - - if ($this->isTimestampValid($lastVisitTimestamp)) { - $daysSinceLastVisit = round(($this->getCurrentTimestamp() - $lastVisitTimestamp) / 86400, $precision = 0); - if ($daysSinceLastVisit < 0) { - $daysSinceLastVisit = 0; - } - } - - return $daysSinceLastVisit; - } - - /** - * @return int|mixed - */ - public function getVisitCount() - { - $visitCount = $this->getParam('_idvc'); - if ($visitCount < 1) { - $visitCount = 1; - } - return $visitCount; - } - - /** * Returns the language the visitor is viewing. * * @return string browser language code, eg. "en-gb,en;q=0.5" @@ -366,10 +298,6 @@ class Request '_ref' => array('', 'string'), '_rcn' => array('', 'string'), '_rck' => array('', 'string'), - '_idts' => array(0, 'int'), - '_viewts' => array(0, 'int'), - '_ects' => array(0, 'int'), - '_idvc' => array(1, 'int'), 'url' => array('', 'string'), 'urlref' => array('', 'string'), 'res' => array(self::UNKNOWN_RESOLUTION, 'string'), diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php index f9c845737d..9f5d90d65a 100644 --- a/core/Tracker/Visit.php +++ b/core/Tracker/Visit.php @@ -65,6 +65,11 @@ class Visit implements VisitInterface protected $visitProperties; /** + * @var VisitProperties + */ + protected $previousVisitProperties; + + /** * @var ArchiveInvalidator */ private $invalidator; @@ -179,6 +184,7 @@ class Visit implements VisitInterface } $isNewVisit = $this->request->getMetadata('CoreHome', 'isNewVisit'); + $this->previousVisitProperties = new VisitProperties($this->request->getMetadata('CoreHome', 'lastKnownVisit') ?: []); // Known visit when: // ( - the visitor has the Piwik cookie with the idcookie ID used by Piwik to match the visitor @@ -211,7 +217,6 @@ class Visit implements VisitInterface $processor->recordLogs($this->visitProperties, $this->request); } - $this->markArchivedReportsAsInvalidIfArchiveAlreadyFinished(); } @@ -251,7 +256,7 @@ class Visit implements VisitInterface // statement at all avoiding potential lock wait time when too many requests try to update the same visit at // same time $visitorRecognizer = StaticContainer::get(VisitorRecognizer::class); - $valuesToUpdate = $visitorRecognizer->removeUnchangedValues($this->visitProperties, $valuesToUpdate); + $valuesToUpdate = $visitorRecognizer->removeUnchangedValues($valuesToUpdate, $this->previousVisitProperties); $this->updateExistingVisit($valuesToUpdate); @@ -607,6 +612,6 @@ class Visit implements VisitInterface private function makeVisitorFacade() { - return Visitor::makeFromVisitProperties($this->visitProperties, $this->request); + return Visitor::makeFromVisitProperties($this->visitProperties, $this->request, $this->previousVisitProperties); } } diff --git a/core/Tracker/Visit/VisitProperties.php b/core/Tracker/Visit/VisitProperties.php index 334950a475..3d64a50e77 100644 --- a/core/Tracker/Visit/VisitProperties.php +++ b/core/Tracker/Visit/VisitProperties.php @@ -21,6 +21,11 @@ class VisitProperties */ private $visitInfo = array(); + public function __construct(array $visitInfo = []) + { + $this->visitInfo = $visitInfo; + } + /** * Returns a visit property, or `null` if none is set. * diff --git a/core/Tracker/Visitor.php b/core/Tracker/Visitor.php index 9a38d2d02a..36aeb7a114 100644 --- a/core/Tracker/Visitor.php +++ b/core/Tracker/Visitor.php @@ -13,18 +13,28 @@ use Piwik\Tracker\Visit\VisitProperties; class Visitor { private $visitorKnown = false; + + /** + * @var VisitProperties + */ public $visitProperties; - public function __construct(VisitProperties $visitProperties, $isVisitorKnown = false) + /** + * @var VisitProperties + */ + public $previousVisitProperties; + + public function __construct(VisitProperties $visitProperties, $isVisitorKnown = false, VisitProperties $previousVisitProperties = null) { $this->visitProperties = $visitProperties; + $this->previousVisitProperties = $previousVisitProperties; $this->setIsVisitorKnown($isVisitorKnown); } - public static function makeFromVisitProperties(VisitProperties $visitProperties, Request $request) + public static function makeFromVisitProperties(VisitProperties $visitProperties, Request $request, VisitProperties $previousVisitProperties = null) { $isKnown = $request->getMetadata('CoreHome', 'isVisitorKnown'); - return new Visitor($visitProperties, $isKnown); + return new Visitor($visitProperties, $isKnown, $previousVisitProperties); } public function setVisitorColumn($column, $value) @@ -41,6 +51,19 @@ class Visitor return false; } + public function getPreviousVisitColumn($column) + { + if (empty($this->previousVisitProperties)) { + return false; + } + + if (array_key_exists($column, $this->previousVisitProperties->getProperties())) { + return $this->previousVisitProperties->getProperty($column); + } + + return false; + } + public function isVisitorKnown() { return $this->visitorKnown === true; diff --git a/core/Tracker/VisitorRecognizer.php b/core/Tracker/VisitorRecognizer.php index e241384419..10fb9b60b9 100644 --- a/core/Tracker/VisitorRecognizer.php +++ b/core/Tracker/VisitorRecognizer.php @@ -111,7 +111,6 @@ class VisitorRecognizer if ($visitRow && count($visitRow) > 0 ) { - $visitProperties->setProperty(self::KEY_ORIGINAL_VISIT_ROW, $visitRow); $visitProperties->setProperty('idvisitor', $visitRow['idvisitor']); $visitProperties->setProperty('user_id', $visitRow['user_id']); @@ -128,14 +127,13 @@ class VisitorRecognizer } } - public function removeUnchangedValues(VisitProperties $visitProperties, $visit) + public function removeUnchangedValues($visit, VisitProperties $originalVisit = null) { - $originalRow = $visitProperties->getProperty(self::KEY_ORIGINAL_VISIT_ROW); - - if (empty($originalRow)) { + if (empty($originalVisit)) { return $visit; } + $originalRow = $originalVisit->getProperties(); if (!empty($originalRow['idvisitor']) && !empty($visit['idvisitor']) && bin2hex($originalRow['idvisitor']) === bin2hex($visit['idvisitor'])) { @@ -240,8 +238,8 @@ class VisitorRecognizer 'visit_exit_idaction_url', 'visit_exit_idaction_name', 'visitor_returning', - 'visitor_days_since_first', - 'visitor_days_since_order', + 'visitor_seconds_since_first', + 'visitor_seconds_since_order', 'visitor_count_visits', 'visit_goal_buyer', |