/** * Records in the DB the association between the visit and this action. * * @param int $idReferrerActionUrl is the ID of the last action done by the current visit. * @param $idReferrerActionName * @param Visitor $visitor */ public function record(Visitor $visitor, $idReferrerActionUrl, $idReferrerActionName) { $this->loadIdsFromLogActionTable(); $visitAction = array('idvisit' => $visitor->getVisitorColumn('idvisit'), 'idsite' => $this->request->getIdSite(), 'idvisitor' => $visitor->getVisitorColumn('idvisitor'), 'idaction_url' => $this->getIdActionUrl(), 'idaction_url_ref' => $idReferrerActionUrl, 'idaction_name_ref' => $idReferrerActionName); /** @var ActionDimension[] $dimensions */ $dimensions = ActionDimension::getAllDimensions(); foreach ($dimensions as $dimension) { $value = $dimension->onNewAction($this->request, $visitor, $this); if ($value !== false) { if (is_float($value)) { $value = Common::forceDotAsSeparatorForDecimalPoint($value); } $visitAction[$dimension->getColumnName()] = $value; } } // idaction_name is NULLable. we only set it when applicable if ($this->isActionHasActionName()) { $visitAction['idaction_name'] = (int) $this->getIdActionName(); } foreach ($this->actionIdsCached as $field => $idAction) { $visitAction[$field] = $idAction === false ? 0 : $idAction; } $customValue = $this->getCustomFloatValue(); if (!empty($customValue)) { $visitAction[self::DB_COLUMN_CUSTOM_FLOAT] = Common::forceDotAsSeparatorForDecimalPoint($customValue); } $visitAction = array_merge($visitAction, $this->customFields); $this->idLinkVisitAction = $this->getModel()->createAction($visitAction); $visitAction['idlink_va'] = $this->idLinkVisitAction; Common::printDebug("Inserted new action:"); $visitActionDebug = $visitAction; $visitActionDebug['idvisitor'] = bin2hex($visitActionDebug['idvisitor']); Common::printDebug($visitActionDebug); }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed */ public function onNewVisit(Request $request, Visitor $visitor, $action) { $referrerUrl = $request->getParam('urlref'); $currentUrl = $request->getParam('url'); $information = $this->getReferrerInformation($referrerUrl, $currentUrl, $request->getIdSite()); return $information['referer_url']; }
public function afterRequestProcessed(VisitProperties $visitProperties, Request $request) { $goalsConverted = $request->getMetadata('Goals', 'goalsConverted'); /** @var Action $action */ $action = $request->getMetadata('Actions', 'action'); // if the visit hasn't already been converted another way (ie, manual goal conversion or ecommerce conversion, // try to convert based on the action) if (empty($goalsConverted) && $action) { $goalsConverted = $this->goalManager->detectGoalsMatchingUrl($request->getIdSite(), $action); $existingGoalsConverted = $request->getMetadata('Goals', 'goalsConverted') ?: array(); $request->setMetadata('Goals', 'goalsConverted', array_merge($existingGoalsConverted, $goalsConverted)); if (!empty($goalsConverted)) { $request->setMetadata('Goals', 'visitIsConverted', true); } } // There is an edge case when: // - two manual goal conversions happen in the same second // - which result in handleExistingVisit throwing the exception // because the UPDATE didn't affect any rows (one row was found, but not updated since no field changed) // - the exception is caught here and will result in a new visit incorrectly // In this case, we cancel the current conversion to be recorded: $isManualGoalConversion = $this->isManualGoalConversion($request); $requestIsEcommerce = $request->getMetadata('Goals', 'isRequestEcommerce'); $visitorNotFoundInDb = $request->getMetadata('CoreHome', 'visitorNotFoundInDb'); if ($visitorNotFoundInDb && ($isManualGoalConversion || $requestIsEcommerce)) { $request->setMetadata('Goals', 'goalsConverted', array()); $request->setMetadata('Goals', 'visitIsConverted', false); } }
/** * @param $valuesToUpdate * @throws VisitorNotFoundInDb */ protected function updateExistingVisit($valuesToUpdate) { $sqlQuery = "UPDATE " . Common::prefixTable('log_visit') . "\n SET %s\n WHERE idsite = ?\n AND idvisit = ?"; // build sql query $updateParts = $sqlBind = array(); foreach ($valuesToUpdate as $name => $value) { // Case where bind parameters don't work if (strpos($value, $name) !== false) { //$name = 'visit_total_events' //$value = 'visit_total_events + 1'; $updateParts[] = " {$name} = {$value} "; } else { $updateParts[] = $name . " = ?"; $sqlBind[] = $value; } } $sqlQuery = sprintf($sqlQuery, implode($updateParts, ', ')); array_push($sqlBind, $this->request->getIdSite(), (int) $this->visitorInfo['idvisit']); $result = Tracker::getDatabase()->query($sqlQuery, $sqlBind); // Debug output if (isset($valuesToUpdate['idvisitor'])) { $valuesToUpdate['idvisitor'] = bin2hex($valuesToUpdate['idvisitor']); } Common::printDebug('Updating existing visit: ' . var_export($valuesToUpdate, true)); if (Tracker::getDatabase()->rowCount($result) == 0) { Common::printDebug("Visitor with this idvisit wasn't found in the DB."); Common::printDebug("{$sqlQuery} --- "); Common::printDebug($sqlBind); throw new VisitorNotFoundInDb("The visitor with idvisitor=" . bin2hex($this->visitorInfo['idvisitor']) . " and idvisit=" . $this->visitorInfo['idvisit'] . " wasn't found in the DB, we fallback to a new visitor"); } }
protected function getNewVisitorInformation($action) { $actionType = $idActionName = $idActionUrl = false; if ($action) { $idActionUrl = $action->getIdActionUrlForEntryAndExitIds(); $idActionName = $action->getIdActionNameForEntryAndExitIds(); $actionType = $action->getActionType(); } $daysSinceFirstVisit = $this->request->getDaysSinceFirstVisit(); $visitCount = $this->request->getVisitCount(); $daysSinceLastVisit = $this->request->getDaysSinceLastVisit(); $daysSinceLastOrder = $this->request->getDaysSinceLastOrder(); $isReturningCustomer = $daysSinceLastOrder !== false; if ($daysSinceLastOrder === false) { $daysSinceLastOrder = 0; } // User settings $userInfo = $this->getSettingsObject(); $userInfo = $userInfo->getInfo(); // Referrer data $referrer = new Referrer(); $referrerUrl = $this->request->getParam('urlref'); $currentUrl = $this->request->getParam('url'); $referrerInfo = $referrer->getReferrerInformation($referrerUrl, $currentUrl, $this->request->getIdSite()); $visitorReturning = $isReturningCustomer ? 2 : ($visitCount > 1 || $this->isVisitorKnown() || $daysSinceLastVisit > 0 ? 1 : 0); $defaultTimeOnePageVisit = Config::getInstance()->Tracker['default_time_one_page_visit']; return array('idsite' => $this->request->getIdSite(), 'visitor_localtime' => $this->request->getLocalTime(), 'idvisitor' => $this->getVisitorIdcookie(), 'visitor_returning' => $visitorReturning, 'visitor_count_visits' => $visitCount, 'visitor_days_since_last' => $daysSinceLastVisit, 'visitor_days_since_order' => $daysSinceLastOrder, 'visitor_days_since_first' => $daysSinceFirstVisit, 'visit_first_action_time' => Tracker::getDatetimeFromTimestamp($this->request->getCurrentTimestamp()), 'visit_last_action_time' => Tracker::getDatetimeFromTimestamp($this->request->getCurrentTimestamp()), 'visit_entry_idaction_url' => (int) $idActionUrl, 'visit_entry_idaction_name' => (int) $idActionName, 'visit_exit_idaction_url' => (int) $idActionUrl, 'visit_exit_idaction_name' => (int) $idActionName, 'visit_total_actions' => in_array($actionType, array(Action::TYPE_PAGE_URL, Action::TYPE_DOWNLOAD, Action::TYPE_OUTLINK, Action::TYPE_SITE_SEARCH, Action::TYPE_EVENT)) ? 1 : 0, 'visit_total_searches' => $actionType == Action::TYPE_SITE_SEARCH ? 1 : 0, 'visit_total_events' => $actionType == Action::TYPE_EVENT ? 1 : 0, 'visit_total_time' => self::cleanupVisitTotalTime($defaultTimeOnePageVisit), 'visit_goal_buyer' => $this->goalManager->getBuyerType(), 'referer_type' => $referrerInfo['referer_type'], 'referer_name' => $referrerInfo['referer_name'], 'referer_url' => $referrerInfo['referer_url'], 'referer_keyword' => $referrerInfo['referer_keyword'], 'config_id' => $userInfo['config_id'], 'config_os' => $userInfo['config_os'], 'config_browser_name' => $userInfo['config_browser_name'], 'config_browser_version' => $userInfo['config_browser_version'], 'config_resolution' => $userInfo['config_resolution'], 'config_pdf' => $userInfo['config_pdf'], 'config_flash' => $userInfo['config_flash'], 'config_java' => $userInfo['config_java'], 'config_director' => $userInfo['config_director'], 'config_quicktime' => $userInfo['config_quicktime'], 'config_realplayer' => $userInfo['config_realplayer'], 'config_windowsmedia' => $userInfo['config_windowsmedia'], 'config_gears' => $userInfo['config_gears'], 'config_silverlight' => $userInfo['config_silverlight'], 'config_cookie' => $userInfo['config_cookie'], 'location_ip' => $this->getVisitorIp(), 'location_browser_lang' => $userInfo['location_browser_lang']); }
/** * @param Request $request */ public function __construct(Request $request) { $this->spamFilter = new ReferrerSpamFilter(); $this->request = $request; $this->idSite = $request->getIdSite(); $userAgent = $request->getUserAgent(); $this->userAgent = Common::unsanitizeInputValue($userAgent); $this->ip = $request->getIp(); }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed */ public function onNewVisit(Request $request, Visitor $visitor, $action) { $referrerUrl = $request->getParam('urlref'); $currentUrl = $request->getParam('url'); $information = $this->getReferrerInformation($referrerUrl, $currentUrl, $request->getIdSite()); if (!empty($information['referer_keyword'])) { return substr($information['referer_keyword'], 0, 255); } return $information['referer_keyword']; }
/** * Returns a 64-bit hash that attemps to identify a user. * Maintaining some privacy by default, eg. prevents the merging of several Piwik serve together for matching across instances.. * * @param $os * @param $browserName * @param $browserVersion * @param $plugin_Flash * @param $plugin_Java * @param $plugin_Director * @param $plugin_Quicktime * @param $plugin_RealPlayer * @param $plugin_PDF * @param $plugin_WindowsMedia * @param $plugin_Gears * @param $plugin_Silverlight * @param $plugin_Cookie * @param $ip * @param $browserLang * @return string */ protected function getConfigHash(Request $request, $os, $browserName, $browserVersion, $plugin_Flash, $plugin_Java, $plugin_Director, $plugin_Quicktime, $plugin_RealPlayer, $plugin_PDF, $plugin_WindowsMedia, $plugin_Gears, $plugin_Silverlight, $plugin_Cookie, $ip, $browserLang) { // prevent the config hash from being the same, across different Piwik instances // (limits ability of different Piwik instances to cross-match users) $salt = SettingsPiwik::getSalt(); $configString = $os . $browserName . $browserVersion . $plugin_Flash . $plugin_Java . $plugin_Director . $plugin_Quicktime . $plugin_RealPlayer . $plugin_PDF . $plugin_WindowsMedia . $plugin_Gears . $plugin_Silverlight . $plugin_Cookie . $ip . $browserLang . $salt; if (!$this->isSameFingerprintsAcrossWebsites) { $configString .= $request->getIdSite(); } $hash = md5($configString, $raw_output = true); return substr($hash, 0, Tracker::LENGTH_BINARY_ID); }
/** * @param Request $request * @param bool|string $ip * @param bool|string $userAgent */ public function __construct(Request $request, $ip = false, $userAgent = false) { if ($ip === false) { $ip = $request->getIp(); } if ($userAgent === false) { $userAgent = $request->getUserAgent(); } $this->request = $request; $this->idSite = $request->getIdSite(); $this->userAgent = $userAgent; $this->ip = $ip; }
/** * @param Request $request * @param bool|string $ip * @param bool|string $userAgent */ public function __construct(Request $request, $ip = false, $userAgent = false) { $this->spamFilter = new ReferrerSpamFilter(); if (false === $ip) { $ip = $request->getIp(); } if (false === $userAgent) { $userAgent = $request->getUserAgent(); } $this->request = $request; $this->idSite = $request->getIdSite(); $this->userAgent = $userAgent; $this->ip = $ip; }
/** * Records in the DB the association between the visit and this action. * * @param int $idReferrerActionUrl is the ID of the last action done by the current visit. * @param $idReferrerActionName * @param Visitor $visitor */ public function record(Visitor $visitor, $idReferrerActionUrl, $idReferrerActionName) { $this->loadIdsFromLogActionTable(); $visitAction = array('idvisit' => $visitor->getVisitorColumn('idvisit'), 'idsite' => $this->request->getIdSite(), 'idvisitor' => $visitor->getVisitorColumn('idvisitor'), 'idaction_url' => $this->getIdActionUrl(), 'idaction_url_ref' => $idReferrerActionUrl, 'idaction_name_ref' => $idReferrerActionName); /** @var ActionDimension[] $dimensions */ $dimensions = ActionDimension::getAllDimensions(); foreach ($dimensions as $dimension) { $value = $dimension->onNewAction($this->request, $visitor, $this); if ($value !== false) { if (is_float($value)) { $value = Common::forceDotAsSeparatorForDecimalPoint($value); } $visitAction[$dimension->getColumnName()] = $value; } } // idaction_name is NULLable. we only set it when applicable if ($this->isActionHasActionName()) { $visitAction['idaction_name'] = (int) $this->getIdActionName(); } foreach ($this->actionIdsCached as $field => $idAction) { $visitAction[$field] = $idAction === false ? 0 : $idAction; } $customValue = $this->getCustomFloatValue(); if (!empty($customValue)) { $visitAction[self::DB_COLUMN_CUSTOM_FLOAT] = Common::forceDotAsSeparatorForDecimalPoint($customValue); } $customVariables = $this->getCustomVariables(); if (!empty($customVariables)) { Common::printDebug("Page level Custom Variables: "); Common::printDebug($customVariables); } $visitAction = array_merge($visitAction, $customVariables); $this->idLinkVisitAction = $this->getModel()->createAction($visitAction); $visitAction['idlink_va'] = $this->idLinkVisitAction; Common::printDebug("Inserted new action:"); $visitActionDebug = $visitAction; $visitActionDebug['idvisitor'] = bin2hex($visitActionDebug['idvisitor']); Common::printDebug($visitActionDebug); /** * Triggered after successfully persisting a [visit action entity](/guides/persistence-and-the-mysql-backend#visit-actions). * * This event is deprecated, use [Dimensions](http://developer.piwik.org/guides/dimensions) instead. * * @param Action $tracker Action The Action tracker instance. * @param array $visitAction The visit action entity that was persisted. Read * [this](/guides/persistence-and-the-mysql-backend#visit-actions) to see what it contains. * @deprecated */ Piwik::postEvent('Tracker.recordAction', array($trackerAction = $this, $visitAction)); }
private function markArchivedReportsAsInvalidIfArchiveAlreadyFinished() { $idSite = (int) $this->request->getIdSite(); $time = $this->request->getCurrentTimestamp(); $timezone = $this->getTimezoneForSite($idSite); if (!isset($timezone)) { return; } $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 $this->invalidator->rememberToInvalidateArchivedReportsLater($idSite, $date); } }
/** * @param $valuesToUpdate * @throws VisitorNotFoundInDb */ protected function updateExistingVisit($valuesToUpdate) { $idSite = $this->request->getIdSite(); $idVisit = (int) $this->visitorInfo['idvisit']; $wasInserted = $this->getModel()->updateVisit($idSite, $idVisit, $valuesToUpdate); // Debug output if (isset($valuesToUpdate['idvisitor'])) { $valuesToUpdate['idvisitor'] = bin2hex($valuesToUpdate['idvisitor']); } if ($wasInserted) { Common::printDebug('Updated existing visit: ' . var_export($valuesToUpdate, true)); } else { throw new VisitorNotFoundInDb("The visitor with idvisitor=" . bin2hex($this->visitorInfo['idvisitor']) . " and idvisit=" . $this->visitorInfo['idvisit'] . " wasn't found in the DB, we fallback to a new visitor"); } }
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; } }
public function recordLogs(VisitProperties $visitProperties, Request $request) { // if we successfully record some data and the date is older than the site's created time, // update the created time so the data will be viewable in the UI $idSite = $request->getIdSite(); $createdTimeTimestamp = $this->getSiteCreatedTime($idSite); if (empty($createdTimeTimestamp)) { return; } $requestTimestamp = Date::factory((int) $request->getCurrentTimestamp()); // replicating old Piwik logic, see: // https://github.com/piwik/piwik/blob/baa6da86266c7c44bc2d65821c7ffe042c2f4716/core/Archive/ArchiveInvalidator.php#L150 // before when this was done during archive invalidation, the date would not have an attached time and // one extra day was subtracted from the minimum. // I am not sure why this is required or if it is still required, but some tests that check the contents // of archive tables will fail w/o this. $requestTimestamp = $requestTimestamp->subDay(1)->setTime('00:00:00'); if ($requestTimestamp->isEarlier($createdTimeTimestamp)) { $this->updateSiteCreatedTime($idSite, $requestTimestamp); } }
/** * Records in the DB the association between the visit and this action. * * @param int $idVisit is the ID of the current visit in the DB table log_visit * @param $visitorIdCookie * @param int $idReferrerActionUrl is the ID of the last action done by the current visit. * @param $idReferrerActionName * @param int $timeSpentReferrerAction is the number of seconds since the last action was done. * It is directly related to idReferrerActionUrl. */ public function record($idVisit, $visitorIdCookie, $idReferrerActionUrl, $idReferrerActionName, $timeSpentReferrerAction) { $this->loadIdsFromLogActionTable(); $visitAction = array('idvisit' => $idVisit, 'idsite' => $this->request->getIdSite(), 'idvisitor' => $visitorIdCookie, 'server_time' => Tracker::getDatetimeFromTimestamp($this->request->getCurrentTimestamp()), 'idaction_url' => $this->getIdActionUrl(), 'idaction_url_ref' => $idReferrerActionUrl, 'idaction_name_ref' => $idReferrerActionName, 'time_spent_ref_action' => $timeSpentReferrerAction); // idaction_name is NULLable. we only set it when applicable if ($this->isActionHasActionName()) { $visitAction['idaction_name'] = (int) $this->getIdActionName(); } foreach ($this->actionIdsCached as $field => $idAction) { $visitAction[$field] = $idAction === false ? 0 : $idAction; } $customValue = $this->getCustomFloatValue(); if (!empty($customValue)) { $visitAction[self::DB_COLUMN_CUSTOM_FLOAT] = $customValue; } $customVariables = $this->getCustomVariables(); if (!empty($customVariables)) { Common::printDebug("Page level Custom Variables: "); Common::printDebug($customVariables); } $visitAction = array_merge($visitAction, $customVariables); $fields = implode(", ", array_keys($visitAction)); $bind = array_values($visitAction); $values = Common::getSqlStringFieldsArray($visitAction); $sql = "INSERT INTO " . Common::prefixTable('log_link_visit_action') . " ({$fields}) VALUES ({$values})"; Tracker::getDatabase()->query($sql, $bind); $this->idLinkVisitAction = Tracker::getDatabase()->lastInsertId(); $visitAction['idlink_va'] = $this->idLinkVisitAction; Common::printDebug("Inserted new action:"); Common::printDebug($visitAction); /** * Triggered after successfully persisting a [visit action entity](/guides/persistence-and-the-mysql-backend#visit-actions). * * @param Action $tracker Action The Action tracker instance. * @param array $visitAction The visit action entity that was persisted. Read * [this](/guides/persistence-and-the-mysql-backend#visit-actions) to see what it contains. */ Piwik::postEvent('Tracker.recordAction', array($trackerAction = $this, $visitAction)); }
/** * Get Cached Custom Dimensions during tracking. Returns only active custom dimensions. * * @param Request $request * @return array * @throws \Piwik\Exception\UnexpectedWebsiteFoundException */ public static function getCachedCustomDimensions(Request $request) { $idSite = $request->getIdSite(); $cache = Cache::getCacheWebsiteAttributes($idSite); if (empty($cache['custom_dimensions'])) { // no custom dimensions set return array(); } return $cache['custom_dimensions']; }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed */ public function getValueForRecordGoal(Request $request, Visitor $visitor) { $referrerTimestamp = $request->getParam('_refts'); $referrerUrl = $request->getParam('_ref'); $referrerCampaignName = trim(urldecode($request->getParam('_rcn'))); $referrerCampaignKeyword = trim(urldecode($request->getParam('_rck'))); // Attributing the correct Referrer to this conversion. // Priority order is as follows: // 0) In some cases, the campaign is not passed from the JS so we look it up from the current visit // 1) Campaign name/kwd parsed in the JS // 2) Referrer URL stored in the _ref cookie // 3) If no info from the cookie, attribute to the current visit referrer Common::printDebug("Attributing a referrer to this Goal..."); // 3) Default values: current referrer $type = $visitor->getVisitorColumn('referer_type'); $name = $visitor->getVisitorColumn('referer_name'); $keyword = $visitor->getVisitorColumn('referer_keyword'); // 0) In some (unknown!?) cases the campaign is not found in the attribution cookie, but the URL ref was found. // In this case we look up if the current visit is credited to a campaign and will credit this campaign rather than the URL ref (since campaigns have higher priority) if (empty($referrerCampaignName) && $type == Common::REFERRER_TYPE_CAMPAIGN && !empty($name)) { // Use default values per above Common::printDebug("Invalid Referrer information found: current visitor seems to have used a campaign, but campaign name was not found in the request."); } elseif (!empty($referrerCampaignName)) { $type = Common::REFERRER_TYPE_CAMPAIGN; $name = $referrerCampaignName; $keyword = $referrerCampaignKeyword; Common::printDebug("Campaign information from 1st party cookie is used."); } elseif (!empty($referrerUrl)) { $idSite = $request->getIdSite(); $referrer = $this->getReferrerInformation($referrerUrl, $currentUrl = '', $idSite); // if the parsed referrer is interesting enough, ie. website or search engine if (in_array($referrer['referer_type'], array(Common::REFERRER_TYPE_SEARCH_ENGINE, Common::REFERRER_TYPE_WEBSITE))) { $type = $referrer['referer_type']; $name = $referrer['referer_name']; $keyword = $referrer['referer_keyword']; Common::printDebug("Referrer URL (search engine or website) is used."); } else { Common::printDebug("No referrer attribution found for this user. Current user's visit referrer is used."); } } else { Common::printDebug("No referrer attribution found for this user. Current user's visit referrer is used."); } $this->setCampaignValuesToLowercase($type, $name, $keyword); $fields = array('referer_type' => $type, 'referer_name' => $name, 'referer_keyword' => $keyword); if (array_key_exists($this->columnName, $fields)) { return $fields[$this->columnName]; } return false; }
/** * Returns true if the last action was not today. * @param VisitProperties $visitor * @return bool */ private function wasLastActionNotToday(VisitProperties $visitProperties, Request $request) { $lastActionTime = $visitProperties->getProperty('visit_last_action_time'); if (empty($lastActionTime)) { return false; } $idSite = $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 = $request->getCurrentTimestamp(); $now = Date::factory((int) $now, $timezone); return $date->toString() !== $now->toString(); }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return mixed */ public function onAnyGoalConversion(Request $request, Visitor $visitor, $action) { return $request->getIdSite(); }