/** * Checks if request URL is excluded * @return bool */ protected function isUrlExcluded() { $site = Cache::getCacheWebsiteAttributes($this->idSite); if (!empty($site['exclude_unknown_urls']) && !empty($site['urls'])) { $url = $this->request->getParam('url'); $parsedUrl = parse_url($url); $trackingUrl = new SiteUrls(); $urls = $trackingUrl->groupUrlsByHost(array($this->idSite => $site['urls'])); $idSites = $trackingUrl->getIdSitesMatchingUrl($parsedUrl, $urls); $isUrlExcluded = !isset($idSites) || !in_array($this->idSite, $idSites); return $isUrlExcluded; } return false; }
/** * We have previously tried to detect the campaign variables in the URL * so at this stage, if the referrer host is the current host, * or if the referrer host is any of the registered URL for this website, * it is considered a direct entry * @return bool */ protected function detectReferrerDirectEntry() { if (empty($this->referrerHost)) { return false; } $urlsByHost = $this->getCachedUrlsByHostAndIdSite(); $directEntry = new SiteUrls(); $matchingSites = $directEntry->getIdSitesMatchingUrl($this->referrerUrlParse, $urlsByHost); if (isset($matchingSites) && is_array($matchingSites) && in_array($this->idsite, $matchingSites)) { $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_DIRECT_ENTRY; return true; } elseif (isset($matchingSites)) { return false; } $site = Cache::getCacheWebsiteAttributes($this->idsite); $excludeUnknowns = $site['exclude_unknown_urls']; // fallback logic if the referrer domain is not known to any site to not break BC if (!$excludeUnknowns && isset($this->currentUrlParse['host'])) { // this might be actually buggy if first thing tracked is eg an outlink and referrer is from that site $currentHost = Common::mb_strtolower($this->currentUrlParse['host']); if ($currentHost == Common::mb_strtolower($this->referrerHost)) { $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_DIRECT_ENTRY; return true; } } return false; }
/** * @dataProvider getTestIdSitesMatchingUrl */ public function test_getIdSitesMatchingUrl($expectedMatchSites, $parsedUrl) { $urlsGroupedByHost = array('apache.piwik' => array('/foo/second/' => array(2), '/foo/sec/' => array(4), '/foo/bar/' => array(1), '/third/' => array(3), '/test/' => array(1, 2), '/' => array(1, 3)), 'example.org' => array('/foo/test/two/' => array(3), '/foo/second/' => array(6), '/' => array(2, 5)), 'example.com' => array('/' => array(3))); $matchedSites = $this->siteUrls->getIdSitesMatchingUrl($parsedUrl, $urlsGroupedByHost); $this->assertSame($expectedMatchSites, $matchedSites); }