Пример #1
0
 /**
  * Returns an array containing the following information:
  * - referer_type
  *        - direct            -- absence of referer URL OR referer URL has the same host
  *        - site                -- based on the referer URL
  *        - search_engine        -- based on the referer 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 referer types
  *
  * @param $refererUrl must be URL Encoded
  * @param $currentUrl
  * @param $idSite
  * @return array
  */
 public function getRefererInformation($refererUrl, $currentUrl, $idSite)
 {
     $this->idsite = $idSite;
     // default values for the referer_* fields
     $refererUrl = Piwik_Common::unsanitizeInputValue($refererUrl);
     if (!empty($refererUrl) && !Piwik_Common::isLookLikeUrl($refererUrl)) {
         $refererUrl = '';
     }
     $currentUrl = Piwik_Tracker_Action::cleanupUrl($currentUrl);
     $this->refererUrl = $refererUrl;
     $this->refererUrlParse = @parse_url($this->refererUrl);
     $this->currentUrlParse = @parse_url($currentUrl);
     $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_DIRECT_ENTRY;
     $this->nameRefererAnalyzed = '';
     $this->keywordRefererAnalyzed = '';
     $this->refererHost = '';
     if (isset($this->refererUrlParse['host'])) {
         $this->refererHost = $this->refererUrlParse['host'];
     }
     $refererDetected = false;
     if (!empty($this->currentUrlParse['host']) && $this->detectRefererCampaign()) {
         $refererDetected = true;
     }
     if (!$refererDetected) {
         if ($this->detectRefererDirectEntry() || $this->detectRefererSearchEngine()) {
             $refererDetected = true;
         }
     }
     if (!empty($this->refererHost) && !$refererDetected) {
         $this->typeRefererAnalyzed = Piwik_Common::REFERER_TYPE_WEBSITE;
         $this->nameRefererAnalyzed = mb_strtolower($this->refererHost, 'UTF-8');
     }
     $refererInformation = array('referer_type' => $this->typeRefererAnalyzed, 'referer_name' => $this->nameRefererAnalyzed, 'referer_keyword' => $this->keywordRefererAnalyzed, 'referer_url' => $this->refererUrl);
     return $refererInformation;
 }