public function onExistingVisit(&$valuesToUpdate, VisitProperties $visitProperties, Request $request)
 {
     $dimensionsToSet = $this->getCustomDimensionsInScope(CustomDimensions::SCOPE_VISIT, $request);
     foreach ($dimensionsToSet as $field => $value) {
         $valuesToUpdate[$field] = $value;
         $visitProperties->setProperty($field, $value);
     }
 }
 private function makeVisitorAndAction($lastActionTimestamp, $currentActionTime, $isVisitorKnown = false)
 {
     $idsite = API::getInstance()->addSite("name", "http://piwik.net/");
     /** @var Request $request */
     list($visit, $request) = $this->prepareVisitWithRequest(array('idsite' => $idsite), $currentActionTime);
     $visitProperties = new VisitProperties();
     $visitProperties->setProperty('visit_last_action_time', Date::factory($lastActionTimestamp)->getTimestamp());
     $request->setMetadata('CoreHome', 'isVisitorKnown', $isVisitorKnown);
     return array($visit, $visitProperties, $request);
 }
Пример #3
0
 /**
  * @param $visitor
  * @param $valuesToUpdate
  * @return mixed
  */
 private function setIdVisitorForExistingVisit($valuesToUpdate)
 {
     // Might update the idvisitor when it was forced or overwritten for this visit
     if (strlen($this->visitProperties->getProperty('idvisitor')) == Tracker::LENGTH_BINARY_ID) {
         $binIdVisitor = $this->visitProperties->getProperty('idvisitor');
         $valuesToUpdate['idvisitor'] = $binIdVisitor;
     }
     // User ID takes precedence and overwrites idvisitor value
     $userId = $this->request->getForcedUserId();
     if ($userId) {
         $userIdHash = $this->request->getUserIdHashed($userId);
         $binIdVisitor = Common::hex2bin($userIdHash);
         $this->visitProperties->setProperty('idvisitor', $binIdVisitor);
         $valuesToUpdate['idvisitor'] = $binIdVisitor;
     }
     return $valuesToUpdate;
 }
Пример #4
0
 public function findKnownVisitor($configId, VisitProperties $visitProperties, Request $request)
 {
     $idSite = $request->getIdSite();
     $idVisitor = $request->getVisitorId();
     $isVisitorIdToLookup = !empty($idVisitor);
     if ($isVisitorIdToLookup) {
         $visitProperties->setProperty('idvisitor', $idVisitor);
         Common::printDebug("Matching visitors with: visitorId=" . bin2hex($idVisitor) . " OR configId=" . bin2hex($configId));
     } else {
         Common::printDebug("Visitor doesn't have the piwik cookie...");
     }
     $persistedVisitAttributes = $this->getVisitFieldsPersist();
     $shouldMatchOneFieldOnly = $this->shouldLookupOneVisitorFieldOnly($isVisitorIdToLookup, $request);
     list($timeLookBack, $timeLookAhead) = $this->getWindowLookupThisVisit($request);
     $visitRow = $this->model->findVisitor($idSite, $configId, $idVisitor, $persistedVisitAttributes, $shouldMatchOneFieldOnly, $isVisitorIdToLookup, $timeLookBack, $timeLookAhead);
     $isNewVisitForced = $request->getParam('new_visit');
     $isNewVisitForced = !empty($isNewVisitForced);
     $enforceNewVisit = $isNewVisitForced || $this->trackerAlwaysNewVisitor;
     if (!$enforceNewVisit && $visitRow && count($visitRow) > 0) {
         // These values will be used throughout the request
         foreach ($persistedVisitAttributes as $field) {
             $visitProperties->setProperty($field, $visitRow[$field]);
         }
         $visitProperties->setProperty('visit_last_action_time', strtotime($visitRow['visit_last_action_time']));
         $visitProperties->setProperty('visit_first_action_time', strtotime($visitRow['visit_first_action_time']));
         // Custom Variables copied from Visit in potential later conversion
         if (!empty($numCustomVarsToRead)) {
             for ($i = 1; $i <= $numCustomVarsToRead; $i++) {
                 if (isset($visitRow['custom_var_k' . $i]) && strlen($visitRow['custom_var_k' . $i])) {
                     $visitProperties->setProperty('custom_var_k' . $i, $visitRow['custom_var_k' . $i]);
                 }
                 if (isset($visitRow['custom_var_v' . $i]) && strlen($visitRow['custom_var_v' . $i])) {
                     $visitProperties->setProperty('custom_var_v' . $i, $visitRow['custom_var_v' . $i]);
                 }
             }
         }
         Common::printDebug("The visitor is known (idvisitor = " . bin2hex($visitProperties->getProperty('idvisitor')) . ",\n                    config_id = " . bin2hex($configId) . ",\n                    idvisit = {$visitProperties->getProperty('idvisit')},\n                    last action = " . date("r", $visitProperties->getProperty('visit_last_action_time')) . ",\n                    first action = " . date("r", $visitProperties->getProperty('visit_first_action_time')) . ",\n                    visit_goal_buyer' = " . $visitProperties->getProperty('visit_goal_buyer') . ")");
         return true;
     } else {
         Common::printDebug("The visitor was not matched with an existing visitor...");
         return false;
     }
 }
Пример #5
0
 public function afterRequestProcessed(VisitProperties $visitProperties, Request $request)
 {
     $ip = $visitProperties->getProperty('location_ip');
     /**
      * Triggered after visits are tested for exclusion so plugins can modify the IP address
      * persisted with a visit.
      *
      * This event is primarily used by the **PrivacyManager** plugin to anonymize IP addresses.
      *
      * @param string &$ip The visitor's IP address.
      */
     $this->eventDispatcher->postEvent('Tracker.setVisitorIp', array(&$ip));
     $visitProperties->setProperty('location_ip', $ip);
 }