diff options
author | dizzy <diosmosis@users.noreply.github.com> | 2021-05-31 03:57:53 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-31 03:57:53 +0300 |
commit | e0417845f8fd7031e00e97c3576415c998abb2ce (patch) | |
tree | bcb32121d164b62229209534538f8ca7c2bf6705 /core | |
parent | 30eec9445b0a2117f80305f7a367121039f04817 (diff) |
Allow overriding some Tracker config by idSite (#17636)
* Allow tracker config to be customized per site (for some configs)
* Update Response.php
* allow few more settings to be overwritten on a per site basis
* idsite parameter may not be specified during Tracker\Request::__construct() (eg, during bulk tracking)
* Fix another test.
* Just make idsite optional for TrackerConfig::getConfigValue() calls.
* try to fix remaining failure
* forgot to add test file
Co-authored-by: Thomas Steur <tsteur@users.noreply.github.com>
Diffstat (limited to 'core')
-rw-r--r-- | core/Tracker/Request.php | 34 | ||||
-rw-r--r-- | core/Tracker/TrackerConfig.php | 12 | ||||
-rw-r--r-- | core/Tracker/Visit.php | 2 | ||||
-rw-r--r-- | core/Tracker/VisitorRecognizer.php | 2 |
4 files changed, 35 insertions, 15 deletions
diff --git a/core/Tracker/Request.php b/core/Tracker/Request.php index 954ca042de..2dd8be5579 100644 --- a/core/Tracker/Request.php +++ b/core/Tracker/Request.php @@ -73,7 +73,6 @@ class Request $this->tokenAuth = $tokenAuth; $this->timestamp = time(); $this->isEmptyRequest = empty($params); - $this->customTimestampDoesNotRequireTokenauthWhenNewerThan = (int) TrackerConfig::getConfigValue('tracking_requests_require_authentication_when_custom_timestamp_newer_than'); // When the 'url' and referrer url parameter are not given, we might be in the 'Simple Image Tracker' mode. // The URL can default to the Referrer, which will be in this case @@ -90,6 +89,9 @@ class Request // check for 4byte utf8 characters in all tracking params and replace them with � if not support by database $this->params = $this->replaceUnsupportedUtf8Chars($this->params); + + $this->customTimestampDoesNotRequireTokenauthWhenNewerThan = (int) TrackerConfig::getConfigValue('tracking_requests_require_authentication_when_custom_timestamp_newer_than', + $this->getIdSiteIfExists()); } protected function replaceUnsupportedUtf8Chars($value, $key=false) @@ -148,7 +150,7 @@ class Request */ protected function authenticateTrackingApi($tokenAuth) { - $shouldAuthenticate = TrackerConfig::getConfigValue('tracking_requests_require_authentication'); + $shouldAuthenticate = TrackerConfig::getConfigValue('tracking_requests_require_authentication', $this->getIdSiteIfExists()); if ($shouldAuthenticate) { try { @@ -238,11 +240,10 @@ class Request public function isRequestExcluded() { - $config = Config::getInstance(); - $tracker = $config->Tracker; + $excludedRequests = TrackerConfig::getConfigValue('exclude_requests', $this->getIdSiteIfExists()); - if (!empty($tracker['exclude_requests'])) { - $excludedRequests = explode(',', $tracker['exclude_requests']); + if (!empty($excludedRequests)) { + $excludedRequests = explode(',', $excludedRequests); $pattern = '/^(.+?)('.SegmentExpression::MATCH_EQUAL.'|' .SegmentExpression::MATCH_NOT_EQUAL.'|' .SegmentExpression::MATCH_CONTAINS.'|' @@ -587,6 +588,15 @@ class Request return $idSite; } + public function getIdSiteIfExists() + { + try { + return $this->getIdSite(); + } catch (UnexpectedWebsiteFoundException $ex) { + return null; + } + } + public function getIdSite() { if (isset($this->idSiteCache)) { @@ -625,7 +635,7 @@ class Request public function shouldUseThirdPartyCookie() { - return (bool)Config::getInstance()->Tracker['use_third_party_id_cookie']; + return TrackerConfig::getConfigValue('use_third_party_id_cookie', $this->getIdSiteIfExists()); } public function getThirdPartyCookieVisitorId() @@ -685,22 +695,22 @@ class Request protected function getCookieName() { - return TrackerConfig::getConfigValue('cookie_name'); + return TrackerConfig::getConfigValue('cookie_name', $this->getIdSiteIfExists()); } protected function getCookieExpire() { - return $this->getCurrentTimestamp() + TrackerConfig::getConfigValue('cookie_expire'); + return $this->getCurrentTimestamp() + TrackerConfig::getConfigValue('cookie_expire', $this->getIdSiteIfExists()); } protected function getCookiePath() { - return TrackerConfig::getConfigValue('cookie_path'); + return TrackerConfig::getConfigValue('cookie_path', $this->getIdSiteIfExists()); } protected function getCookieDomain() { - return TrackerConfig::getConfigValue('cookie_domain'); + return TrackerConfig::getConfigValue('cookie_domain', $this->getIdSiteIfExists()); } /** @@ -716,7 +726,7 @@ class Request { $found = false; - if (TrackerConfig::getConfigValue('enable_userid_overwrites_visitorid')) { + if (TrackerConfig::getConfigValue('enable_userid_overwrites_visitorid', $this->getIdSiteIfExists())) { // If User ID is set it takes precedence $userId = $this->getForcedUserId(); if ($userId) { diff --git a/core/Tracker/TrackerConfig.php b/core/Tracker/TrackerConfig.php index 3c998405f1..3647bc7b87 100644 --- a/core/Tracker/TrackerConfig.php +++ b/core/Tracker/TrackerConfig.php @@ -25,9 +25,13 @@ class TrackerConfig Config::getInstance()->Tracker = $section; } - public static function getConfigValue($name) + public static function getConfigValue($name, $idSite = null) { $config = self::getConfig(); + if (!empty($idSite)) { + $siteSpecificConfig = self::getSiteSpecificConfig($idSite); + $config = array_merge($config, $siteSpecificConfig); + } return $config[$name]; } @@ -35,4 +39,10 @@ class TrackerConfig { return Config::getInstance()->Tracker; } + + private static function getSiteSpecificConfig($idSite) + { + $key = 'Tracker_' . $idSite; + return Config::getInstance()->$key; + } } diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php index cfc2a4830f..1b8d9aefd4 100644 --- a/core/Tracker/Visit.php +++ b/core/Tracker/Visit.php @@ -586,7 +586,7 @@ class Visit implements VisitInterface $valuesToUpdate['idvisitor'] = $this->request->getVisitorId(); } - if (TrackerConfig::getConfigValue('enable_userid_overwrites_visitorid')) { + if (TrackerConfig::getConfigValue('enable_userid_overwrites_visitorid', $this->request->getIdSiteIfExists())) { // User ID takes precedence and overwrites idvisitor value $userId = $this->request->getForcedUserId(); if ($userId) { diff --git a/core/Tracker/VisitorRecognizer.php b/core/Tracker/VisitorRecognizer.php index 3c670d0050..89e159a9ef 100644 --- a/core/Tracker/VisitorRecognizer.php +++ b/core/Tracker/VisitorRecognizer.php @@ -104,7 +104,7 @@ class VisitorRecognizer $shouldMatchOneFieldOnly = $this->shouldLookupOneVisitorFieldOnly($isVisitorIdToLookup, $request); list($timeLookBack, $timeLookAhead) = $this->getWindowLookupThisVisit($request); - $maxActions = TrackerConfig::getConfigValue('create_new_visit_after_x_actions'); + $maxActions = TrackerConfig::getConfigValue('create_new_visit_after_x_actions', $request->getIdSiteIfExists()); $visitRow = $this->model->findVisitor($idSite, $configId, $idVisitor, $userId, $persistedVisitAttributes, $shouldMatchOneFieldOnly, $isVisitorIdToLookup, $timeLookBack, $timeLookAhead); |