Exemple #1
0
 /**
  * Returns an array containing the following information:
  * - referer_type
  *        - direct            -- absence of referrer URL OR referrer URL has the same host
  *        - site                -- based on the referrer URL
  *        - search_engine        -- based on the referrer URL
  *        - campaign            -- based on campaign URL parameter
  *
  * - referer_name
  *         - ()
  *         - piwik.net            -- site host name
  *         - google.fr            -- search engine host name
  *         - adwords-search    -- campaign name
  *
  * - referer_keyword
  *         - ()
  *         - ()
  *         - my keyword
  *         - my paid keyword
  *         - ()
  *         - ()
  *
  * - referer_url : the same for all the referrer types
  *
  * @param string $referrerUrl must be URL Encoded
  * @param string $currentUrl
  * @param int $idSite
  * @return array
  */
 public function getReferrerInformation($referrerUrl, $currentUrl, $idSite)
 {
     $this->idsite = $idSite;
     // default values for the referer_* fields
     $referrerUrl = Common::unsanitizeInputValue($referrerUrl);
     if (!empty($referrerUrl) && !UrlHelper::isLookLikeUrl($referrerUrl)) {
         $referrerUrl = '';
     }
     $currentUrl = PageUrl::cleanupUrl($currentUrl);
     $this->referrerUrl = $referrerUrl;
     $this->referrerUrlParse = @parse_url($this->referrerUrl);
     $this->currentUrlParse = @parse_url($currentUrl);
     $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_DIRECT_ENTRY;
     $this->nameReferrerAnalyzed = '';
     $this->keywordReferrerAnalyzed = '';
     $this->referrerHost = '';
     if (isset($this->referrerUrlParse['host'])) {
         $this->referrerHost = $this->referrerUrlParse['host'];
     }
     $referrerDetected = $this->detectReferrerCampaign();
     if (!$referrerDetected) {
         if ($this->detectReferrerDirectEntry() || $this->detectReferrerSearchEngine()) {
             $referrerDetected = true;
         }
     }
     if (!empty($this->referrerHost) && !$referrerDetected) {
         $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_WEBSITE;
         $this->nameReferrerAnalyzed = Common::mb_strtolower($this->referrerHost);
     }
     $referrerInformation = array('referer_type' => $this->typeReferrerAnalyzed, 'referer_name' => $this->nameReferrerAnalyzed, 'referer_keyword' => $this->keywordReferrerAnalyzed, 'referer_url' => $this->referrerUrl);
     return $referrerInformation;
 }
Exemple #2
0
 /**
  * Returns the extracted utm details from the url
  * @param  string  $currentUrl 
  * @param  int     $idSite     
  * @param  Request $request    
  * @return array            
  */
 private function getCampaignInformation($currentUrl, $idSite, Request $request)
 {
     $cacheKey = $currentUrl . $idSite;
     if (isset(self::$cachedReferrer[$cacheKey])) {
         return self::$cachedReferrer[$cacheKey];
     }
     $currentUrl = PageUrl::cleanupUrl($currentUrl);
     $this->currentUrlParse = @parse_url($currentUrl);
     $utmInformation = $this->extractUtmDetailsFromUrl();
     self::$cachedReferrer[$cacheKey] = $utmInformation;
     return $utmInformation;
 }
Exemple #3
0
 /**
  * Returns an array containing the following information:
  * - referer_type
  *        - direct            -- absence of referrer URL OR referrer URL has the same host
  *        - site                -- based on the referrer URL
  *        - search_engine        -- based on the referrer URL
  *        - campaign            -- based on campaign URL parameter
  *
  * - referer_name
  *         - ()
  *         - piwik.net            -- site host name
  *         - google.fr            -- search engine host name
  *         - adwords-search    -- campaign name
  *
  * - referer_keyword
  *         - ()
  *         - ()
  *         - my keyword
  *         - my paid keyword
  *         - ()
  *         - ()
  *
  * - referer_url : the same for all the referrer types
  *
  * @param string $referrerUrl must be URL Encoded
  * @param string $currentUrl
  * @param int $idSite
  * @return array
  */
 protected function getReferrerInformation($referrerUrl, $currentUrl, $idSite, Request $request)
 {
     $cacheKey = $referrerUrl . $currentUrl . $idSite;
     if (isset(self::$cachedReferrer[$cacheKey])) {
         return self::$cachedReferrer[$cacheKey];
     }
     $this->idsite = $idSite;
     // default values for the referer_* fields
     $referrerUrl = Common::unsanitizeInputValue($referrerUrl);
     if (!empty($referrerUrl) && !UrlHelper::isLookLikeUrl($referrerUrl)) {
         $referrerUrl = '';
     }
     $currentUrl = PageUrl::cleanupUrl($currentUrl);
     $this->referrerUrl = $referrerUrl;
     $this->referrerUrlParse = @parse_url($this->referrerUrl);
     $this->currentUrlParse = @parse_url($currentUrl);
     $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_DIRECT_ENTRY;
     $this->nameReferrerAnalyzed = '';
     $this->keywordReferrerAnalyzed = '';
     $this->referrerHost = '';
     if (isset($this->referrerUrlParse['host'])) {
         $this->referrerHost = $this->referrerUrlParse['host'];
     }
     $referrerDetected = $this->detectReferrerCampaign($request);
     if (!$referrerDetected) {
         if ($this->detectReferrerDirectEntry() || $this->detectReferrerSearchEngine()) {
             $referrerDetected = true;
         }
     }
     if (!$referrerDetected && !empty($this->referrerHost)) {
         $this->typeReferrerAnalyzed = Common::REFERRER_TYPE_WEBSITE;
         $this->nameReferrerAnalyzed = Common::mb_strtolower($this->referrerHost);
         $urlsByHost = $this->getCachedUrlsByHostAndIdSite();
         $directEntry = new SiteUrls();
         $path = $directEntry->getPathMatchingUrl($this->referrerUrlParse, $urlsByHost);
         if (!empty($path) && $path !== '/') {
             $this->nameReferrerAnalyzed .= rtrim($path, '/');
         }
     }
     $referrerInformation = array('referer_type' => $this->typeReferrerAnalyzed, 'referer_name' => $this->nameReferrerAnalyzed, 'referer_keyword' => $this->keywordReferrerAnalyzed, 'referer_url' => $this->referrerUrl);
     self::$cachedReferrer[$cacheKey] = $referrerInformation;
     return $referrerInformation;
 }
 protected function detectSiteSearch($originalUrl)
 {
     $website = Cache::getCacheWebsiteAttributes($this->request->getIdSite());
     if (empty($website['sitesearch'])) {
         Common::printDebug("Internal 'Site Search' tracking is not enabled for this site. ");
         return false;
     }
     $actionName = $url = $categoryName = $count = false;
     $originalUrl = PageUrl::cleanupUrl($originalUrl);
     // Detect Site search from Tracking API parameters rather than URL
     $searchKwd = $this->request->getParam('search');
     if (!empty($searchKwd)) {
         $actionName = $searchKwd;
         $isCategoryName = $this->request->getParam('search_cat');
         if (!empty($isCategoryName)) {
             $categoryName = $isCategoryName;
         }
         $isCount = $this->request->getParam('search_count');
         if ($this->isValidSearchCount($isCount)) {
             $count = $isCount;
         }
     }
     if (empty($actionName)) {
         $parsedUrl = @parse_url($originalUrl);
         // Detect Site Search from URL query parameters
         if (!empty($parsedUrl['query']) || !empty($parsedUrl['fragment'])) {
             // array($url, $actionName, $categoryName, $count);
             $searchInfo = $this->detectSiteSearchFromUrl($website, $parsedUrl);
             if (!empty($searchInfo)) {
                 list($url, $actionName, $categoryName, $count) = $searchInfo;
             }
         }
     }
     $actionName = trim($actionName);
     $categoryName = trim($categoryName);
     if (empty($actionName)) {
         Common::printDebug("(this is not a Site Search request)");
         return false;
     }
     Common::printDebug("Detected Site Search keyword '{$actionName}'. ");
     if (!empty($categoryName)) {
         Common::printDebug("- Detected Site Search Category '{$categoryName}'. ");
     }
     if ($count !== false) {
         Common::printDebug("- Search Results Count was '{$count}'. ");
     }
     if ($url != $originalUrl) {
         Common::printDebug("NOTE: The Page URL was changed / removed, during the Site Search detection, was '{$originalUrl}', now is '{$url}'");
     }
     return array($actionName, $url, $categoryName, $count);
 }