diff options
author | diosmosis <diosmosis@users.noreply.github.com> | 2019-05-10 11:50:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-10 11:50:56 +0300 |
commit | c6eb52339f3fc496ac43b55c4a0de8d161edbff4 (patch) | |
tree | c05d34d97ea14cdb454e5ca3ff961c9449e53095 /plugins/SitesManager | |
parent | a4c8dc92994ccfd5775d080a4f63cb095ab95e19 (diff) |
Overwrite direct entry referrer information if campaign referrer is found in later request. (#14273)
* Overwrite direct entry referrer information if campaign referrer is found in later request.
* Update for non-campaign referrers as well.
* test comment tweaks
* Add current tracking URL into site urls in case website has no main url.
* Fix a couple issues and start adding tests.
* More tests and a fix.
* Apply review feedback.
* Fix couple tests.
* Fix referrer tests.
* try to fix random failure
* Add note to README.
Diffstat (limited to 'plugins/SitesManager')
-rw-r--r-- | plugins/SitesManager/SiteUrls.php | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/plugins/SitesManager/SiteUrls.php b/plugins/SitesManager/SiteUrls.php index 33e2e4844a..54153d42e0 100644 --- a/plugins/SitesManager/SiteUrls.php +++ b/plugins/SitesManager/SiteUrls.php @@ -10,6 +10,8 @@ namespace Piwik\Plugins\SitesManager; use Piwik\Cache; use Piwik\Common; +use Piwik\Tracker\Request; +use Piwik\Tracker\Visitor; class SiteUrls { @@ -51,35 +53,49 @@ class SiteUrls foreach ($siteUrls as $idSite => $urls) { $idSite = (int) $idSite; foreach ($urls as $url) { - $urlParsed = @parse_url($url); + $this->addUrlByHost($allUrls, $idSite, $url); + } + } - if ($urlParsed === false || !isset($urlParsed['host'])) { - continue; - } + $this->sortUrlsByHost($allUrls); - $host = $this->toCanonicalHost($urlParsed['host']); - $path = $this->getCanonicalPathFromParsedUrl($urlParsed); + return $allUrls; + } - if (!isset($allUrls[$host])) { - $allUrls[$host] = array(); - } + private function addUrlByHost(&$allUrls, $idSite, $url, $addPath = true) + { + $urlParsed = @parse_url($url); - if (!isset($allUrls[$host][$path])) { - $allUrls[$host][$path] = array(); - } + if ($urlParsed === false || !isset($urlParsed['host'])) { + return; + } - if (!in_array($idSite, $allUrls[$host][$path])) { - $allUrls[$host][$path][] = $idSite; - } - } + $host = $this->toCanonicalHost($urlParsed['host']); + $path = $this->getCanonicalPathFromParsedUrl($urlParsed); + + if (!isset($allUrls[$host])) { + $allUrls[$host] = array(); + } + + if (!$addPath) { + $path = '/'; + } + + if (!isset($allUrls[$host][$path])) { + $allUrls[$host][$path] = array(); } + if (!in_array($idSite, $allUrls[$host][$path])) { + $allUrls[$host][$path][] = $idSite; + } + } + + private function sortUrlsByHost(&$allUrls) + { foreach ($allUrls as $host => $paths) { uksort($paths, array($this, 'sortByPathDepth')); $allUrls[$host] = $paths; } - - return $allUrls; } public function getIdSitesMatchingUrl($parsedUrl, $urlsGroupedByHost) @@ -172,6 +188,14 @@ class SiteUrls return Cache::getLazyCache(); } + public function addRequestUrlToSiteUrls(&$allUrls, Request $request) + { + $idSite = $request->getIdSite(); + $url = $request->getParam('url'); + + $this->addUrlByHost($allUrls, $idSite, $url, $addPath = false); + } + private function sortByPathDepth($pathA, $pathB) { // list first the paths with most '/' , and list path = '/' last |