diff options
-rwxr-xr-x | config/global.ini.php | 6 | ||||
-rw-r--r-- | core/Tracker/VisitorRecognizer.php | 10 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/Tracker/VisitorRecognizerTest.php | 54 | ||||
-rw-r--r-- | tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png | 4 |
4 files changed, 67 insertions, 7 deletions
diff --git a/config/global.ini.php b/config/global.ini.php index e741746663..461a4abddd 100755 --- a/config/global.ini.php +++ b/config/global.ini.php @@ -881,6 +881,12 @@ create_new_visit_when_website_referrer_changes = 0 ; Whether to force a new visit at midnight for every visitor. Default 1. create_new_visit_after_midnight = 1 +; Will force the creation of a new visit once a visit had this many actions. +; Increasing this number can slow down the tracking in Matomo and put more load on the database. +; Increase this limit if it's expected that you have visits with more than this many actions. +; Set to 0 or a negative value to allow unlimited actions. +create_new_visit_after_x_actions = 10000 + ; maximum length of a Page Title or a Page URL recorded in the log_action.name table page_maximum_length = 1024; diff --git a/core/Tracker/VisitorRecognizer.php b/core/Tracker/VisitorRecognizer.php index 7b4efdd0c1..3c670d0050 100644 --- a/core/Tracker/VisitorRecognizer.php +++ b/core/Tracker/VisitorRecognizer.php @@ -104,7 +104,17 @@ class VisitorRecognizer $shouldMatchOneFieldOnly = $this->shouldLookupOneVisitorFieldOnly($isVisitorIdToLookup, $request); list($timeLookBack, $timeLookAhead) = $this->getWindowLookupThisVisit($request); + $maxActions = TrackerConfig::getConfigValue('create_new_visit_after_x_actions'); + $visitRow = $this->model->findVisitor($idSite, $configId, $idVisitor, $userId, $persistedVisitAttributes, $shouldMatchOneFieldOnly, $isVisitorIdToLookup, $timeLookBack, $timeLookAhead); + + if (!empty($maxActions) && $maxActions > 0 + && !empty($visitRow['visit_total_actions']) + && $maxActions <= $visitRow['visit_total_actions']) { + $this->visitRow = false; + return false; + } + $this->visitRow = $visitRow; if ($visitRow diff --git a/tests/PHPUnit/Integration/Tracker/VisitorRecognizerTest.php b/tests/PHPUnit/Integration/Tracker/VisitorRecognizerTest.php index 42ab0c07a4..20a45a1a4d 100644 --- a/tests/PHPUnit/Integration/Tracker/VisitorRecognizerTest.php +++ b/tests/PHPUnit/Integration/Tracker/VisitorRecognizerTest.php @@ -8,10 +8,15 @@ namespace Piwik\Tests\Integration\Tracker; +use Matomo\Network\IP; use Piwik\Common; +use Piwik\Config; +use Piwik\Date; use Piwik\EventDispatcher; +use Piwik\Tests\Framework\Fixture; use Piwik\Tracker\Model; use Piwik\Tests\Framework\TestCase\IntegrationTestCase; +use Piwik\Tracker\Request; use Piwik\Tracker\Visit\VisitProperties; use Piwik\Tracker\VisitorRecognizer; @@ -30,15 +35,54 @@ class VisitorRecognizerTest extends IntegrationTestCase parent::setUp(); $this->recognizer = new VisitorRecognizer(true, 1800, 24000, new Model(), EventDispatcher::getInstance()); + + Fixture::createWebsite('2020-01-01 02:03:04'); } - private function getVisitProperties() + public function test_findKnownVisitor_whenNotExceededMaxActionsLimitFindsVisitor() { - $visit = new VisitProperties(); - $visit->setProperty('idvisit', '321'); - $visit->setProperty('idvisitor', Common::hex2bin('1234567890234567')); + $this->assertNull($this->recognizer->getLastKnownVisit()); + + $configId = $this->createVisit(9999); + $visitor = $this->findKnownVisitor($configId); + $this->assertTrue($visitor); + $this->assertNotEmpty($this->recognizer->getLastKnownVisit()); + } + + private function findKnownVisitor($configId) + { + $visitProperties = new VisitProperties(); + $request = new Request(['idsite' => 1, 'cid' => $configId, 'uid' => $configId]); + + return $this->recognizer->findKnownVisitor($configId, $visitProperties, $request); + } - return $visit; + private function createVisit($maxTotalActions) + { + $configId = '1234567812345678'; + $request = new Request(['idsite' => 1, 'uid' => $configId]); + $model = new Model(); + $model->createVisit(array( + 'config_id' => Common::hex2bin($configId), + 'idsite' => 1, + 'user_id' => $configId, + 'visit_total_time' => 1, + 'visit_total_actions' => $maxTotalActions, + 'visit_last_action_time' => Date::now()->getDatetime(), + 'visit_first_action_time' => Date::now()->getDatetime(), + 'idvisitor' => $request->getVisitorId(), + 'location_ip' => IP::fromStringIP('1.1.1.1')->toBinary() + )); + + return $configId; + } + + public function test_findKnownVisitor_whenExceededMaxActionsLimitFindsNotVisitor() + { + $configId = $this->createVisit(10000); + $visitor = $this->findKnownVisitor($configId); + $this->assertFalse($visitor); + $this->assertFalse($this->recognizer->getLastKnownVisit()); } public function test_removeUnchangedValues_newVisit_shouldNotChangeAnything() diff --git a/tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png b/tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png index 38eadbd20d..00bd8d8879 100644 --- a/tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png +++ b/tests/UI/expected-screenshots/UIIntegrationTest_admin_diagnostics_configfile.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7880424f69eb61c03a65392301e90718a153ceab553957323bb5a2a2f24be153 -size 4571815 +oid sha256:02e058bca47f243c5eba0f4f57ff7848ba8b4c02123569918fa6e9c21c9231f0 +size 4598472 |