diff options
author | mattab <matthieu.aubry@gmail.com> | 2015-06-26 04:09:50 +0300 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2015-06-26 04:09:50 +0300 |
commit | 56e1bc7ddf6e13caa612a39a10a86fb2e60dee90 (patch) | |
tree | 71c00f3e0914d06e4dcbb45767daf5305f47e120 /core/Tracker/Visit.php | |
parent | 83023ea9e73cdd61e1953659b4cfa5b5b1c1b0e7 (diff) |
Refs #8218 Do not create a new visit when it is a ping request.
Diffstat (limited to 'core/Tracker/Visit.php')
-rw-r--r-- | core/Tracker/Visit.php | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php index 3811e81c9b..4c5bc200b0 100644 --- a/core/Tracker/Visit.php +++ b/core/Tracker/Visit.php @@ -9,9 +9,9 @@ namespace Piwik\Tracker; +use Piwik\Archive\ArchiveInvalidator; use Piwik\Common; use Piwik\Config; -use Piwik\Archive\ArchiveInvalidator; use Piwik\Date; use Piwik\Exception\UnexpectedWebsiteFoundException; use Piwik\Network\IPUtils; @@ -128,7 +128,7 @@ class Visit implements VisitInterface } elseif ($isManualGoalConversion) { // this request is from the JS call to piwikTracker.trackGoal() $someGoalsConverted = $this->goalManager->detectGoalId($this->request->getIdSite()); - $visitIsConverted = $someGoalsConverted; + $visitIsConverted = $someGoalsConverted; // if we find a idgoal in the URL, but then the goal is not valid, this is most likely a fake request if (!$someGoalsConverted) { @@ -142,7 +142,7 @@ class Visit implements VisitInterface $action->writeDebugInfo(); $someGoalsConverted = $this->goalManager->detectGoalsMatchingUrl($this->request->getIdSite(), $action); - $visitIsConverted = $someGoalsConverted; + $visitIsConverted = $someGoalsConverted; $action->loadIdsFromLogActionTable(); } @@ -151,7 +151,7 @@ class Visit implements VisitInterface * Visitor recognition */ $visitorId = $this->getSettingsObject()->getConfigId(); - $visitor = new Visitor($this->request, $visitorId, $this->visitorInfo, $this->visitorCustomVariables); + $visitor = new Visitor($this->request, $visitorId, $this->visitorInfo, $this->visitorCustomVariables); $visitor->recognize(); $this->visitorInfo = $visitor->getVisitorInfo(); @@ -169,10 +169,11 @@ class Visit implements VisitInterface // on a ping request that is received before the standard visit length, we just update the visit time w/o // adding a new action if ($this->isPingRequest()) { + Common::printDebug("-> ping=1 request: we do not track a new action."); $action = null; } - $idReferrerActionUrl = $this->visitorInfo['visit_exit_idaction_url']; + $idReferrerActionUrl = $this->visitorInfo['visit_exit_idaction_url']; $idReferrerActionName = $this->visitorInfo['visit_exit_idaction_name']; try { @@ -207,6 +208,14 @@ class Visit implements VisitInterface // - the visitor doesn't have the Piwik cookie, and couldn't be matched in @see recognizeTheVisitor() // - the visitor does have the Piwik cookie but the idcookie and idvisit found in the cookie didn't match to any existing visit in the DB if ($isNewVisit) { + + // When a ping request is received more than 30 min after the last request/ping, + // we choose not to create a new visit. + if ($this->isPingRequest()) { + Common::printDebug("-> ping=1 request: we do _not_ create a new visit."); + return; + } + $this->handleNewVisit($visitor, $action, $visitIsConverted); if (!is_null($action)) { $action->record($visitor, 0, 0); @@ -389,7 +398,8 @@ class Visit implements VisitInterface protected function getSettingsObject() { if (is_null($this->userSettings)) { - $this->userSettings = new Settings($this->request, $this->getVisitorIp(), SettingsPiwik::isSameFingerprintAcrossWebsites()); + $this->userSettings = new Settings($this->request, $this->getVisitorIp(), + SettingsPiwik::isSameFingerprintAcrossWebsites()); } return $this->userSettings; @@ -404,8 +414,8 @@ class Visit implements VisitInterface $lastActionTime = $visitor->getVisitorColumn('visit_last_action_time'); return isset($lastActionTime) - && false !== $lastActionTime - && ($lastActionTime > ($this->request->getCurrentTimestamp() - Config::getInstance()->Tracker['visit_standard_length'])); + && false !== $lastActionTime + && ($lastActionTime > ($this->request->getCurrentTimestamp() - Config::getInstance()->Tracker['visit_standard_length'])); } /** @@ -421,16 +431,16 @@ class Visit implements VisitInterface return false; } - $idSite = $this->request->getIdSite(); + $idSite = $this->request->getIdSite(); $timezone = $this->getTimezoneForSite($idSite); if (empty($timezone)) { throw new UnexpectedWebsiteFoundException('An unexpected website was found, check idSite in the request'); } - $date = Date::factory((int) $lastActionTime, $timezone); - $now = $this->request->getCurrentTimestamp(); - $now = Date::factory((int) $now, $timezone); + $date = Date::factory((int)$lastActionTime, $timezone); + $now = $this->request->getCurrentTimestamp(); + $now = Date::factory((int)$now, $timezone); return $date->toString() !== $now->toString(); } @@ -467,8 +477,8 @@ class Visit implements VisitInterface */ protected function updateExistingVisit($valuesToUpdate) { - $idSite = $this->request->getIdSite(); - $idVisit = (int) $this->visitorInfo['idvisit']; + $idSite = $this->request->getIdSite(); + $idVisit = (int)$this->visitorInfo['idvisit']; $wasInserted = $this->getModel()->updateVisit($idSite, $idVisit, $valuesToUpdate); @@ -505,7 +515,7 @@ class Visit implements VisitInterface { $idVisitor = $this->getVisitorIdcookie($visitor); $visitorIp = $this->getVisitorIp(); - $configId = $this->getSettingsObject()->getConfigId(); + $configId = $this->getSettingsObject()->getConfigId(); $this->visitorInfo = array(); $visitor->clearVisitorInfo(); @@ -533,11 +543,13 @@ class Visit implements VisitInterface $valuesToUpdate = $this->setIdVisitorForExistingVisit($visitor, $valuesToUpdate); - $dimensions = $this->getAllVisitDimensions(); - $valuesToUpdate = $this->triggerHookOnDimensions($dimensions, 'onExistingVisit', $visitor, $action, $valuesToUpdate); + $dimensions = $this->getAllVisitDimensions(); + $valuesToUpdate = $this->triggerHookOnDimensions($dimensions, 'onExistingVisit', $visitor, $action, + $valuesToUpdate); if ($visitIsConverted) { - $valuesToUpdate = $this->triggerHookOnDimensions($dimensions, 'onConvertedVisit', $visitor, $action, $valuesToUpdate); + $valuesToUpdate = $this->triggerHookOnDimensions($dimensions, 'onConvertedVisit', $visitor, $action, + $valuesToUpdate); } // Custom Variables overwrite previous values on each page view @@ -597,7 +609,8 @@ class Visit implements VisitInterface $dimensionNames[] = $dimension->getColumnName(); } - Common::printDebug("Following dimensions have been collected from plugins: " . implode(", ", $dimensionNames)); + Common::printDebug("Following dimensions have been collected from plugins: " . implode(", ", + $dimensionNames)); } return self::$dimensions; @@ -625,7 +638,7 @@ class Visit implements VisitInterface // User ID takes precedence and overwrites idvisitor value $userId = $this->request->getForcedUserId(); if ($userId) { - $userIdHash = $this->request->getUserIdHashed($userId); + $userIdHash = $this->request->getUserIdHashed($userId); $binIdVisitor = Common::hex2bin($userIdHash); $visitor->setVisitorColumn('idvisitor', $binIdVisitor); $valuesToUpdate['idvisitor'] = $binIdVisitor; @@ -667,7 +680,8 @@ class Visit implements VisitInterface return true; } - $shouldForceNewVisit = $this->triggerPredicateHookOnDimensions($this->getAllVisitDimensions(), 'shouldForceNewVisit', $visitor, $action); + $shouldForceNewVisit = $this->triggerPredicateHookOnDimensions($this->getAllVisitDimensions(), + 'shouldForceNewVisit', $visitor, $action); if ($shouldForceNewVisit) { return true; } @@ -677,8 +691,8 @@ class Visit implements VisitInterface private function markArchivedReportsAsInvalidIfArchiveAlreadyFinished() { - $idSite = (int) $this->request->getIdSite(); - $time = $this->request->getCurrentTimestamp(); + $idSite = (int)$this->request->getIdSite(); + $time = $this->request->getCurrentTimestamp(); $timezone = $this->getTimezoneForSite($idSite); @@ -686,7 +700,7 @@ class Visit implements VisitInterface return; } - $date = Date::factory((int) $time, $timezone); + $date = Date::factory((int)$time, $timezone); if (!$date->isToday()) { // we don't have to handle in case date is in future as it is not allowed by tracker $invalidReport = new ArchiveInvalidator(); |