Example #1
0
 /**
  * Parse referer URL
  *
  * @param string $refererUrl
  * @param string $pageUrl
  * @return Referer
  */
 public function parse($refererUrl, $pageUrl = null)
 {
     $refererParts = static::parseUrl($refererUrl);
     if (!$refererParts) {
         return Referer::createInvalid();
     }
     $pageUrlParts = static::parseUrl($pageUrl);
     if ($pageUrlParts && $pageUrlParts['host'] === $refererParts['host'] || in_array($refererParts['host'], $this->internalHosts)) {
         return Referer::createInternal();
     }
     foreach ($this->internalHosts as $internalHost) {
         if ('*.' !== substr($internalHost, 0, 2)) {
             continue;
         }
         $domain_parts = explode('.', $refererParts['host']);
         if (is_array($domain_parts) && count($domain_parts) >= 2 && implode('.', array_slice($domain_parts, count($domain_parts) - 2, 2)) == substr($internalHost, 2, strlen($internalHost))) {
             return Referer::createInternal();
         }
     }
     $referer = $this->lookup($refererParts['host'], $refererParts['path']);
     if (!$referer) {
         return Referer::createUnknown();
     }
     $searchTerm = null;
     if ($referer['parameters']) {
         parse_str($refererParts['query'], $queryParts);
         foreach ($referer['parameters'] as $parameter) {
             $searchTerm = isset($queryParts[$parameter]) ? $queryParts[$parameter] : $searchTerm;
         }
     }
     return Referer::createKnown($referer['medium'], $referer['source'], $searchTerm);
 }
 /**
  * @return null|string
  */
 public function getDescription()
 {
     if ($this->isGoogleOrganic()) {
         return 'Google Orgânico';
     } elseif ($this->isGoogleAds()) {
         return 'Google Ads';
     } elseif ($this->isGoogleCampaign()) {
         return 'Google Campanha';
     } elseif ($this->isExternalSearch()) {
         return $this->parsedUrl->getMedium() . ': ' . $this->parsedUrl->getSource();
     } elseif ($this->isExternalUnknownSource()) {
         $sourceUrl = parse_url(\Yii::$app->request->referrer);
         $sourceUrl = $sourceUrl['scheme'] . '://' . $sourceUrl['host'];
         return 'Site Externo: ' . $sourceUrl;
     } else {
         return 'Acesso Direto';
     }
 }
Example #3
0
 /**
  * Parse referer URL
  *
  * @param string $refererUrl
  * @param string $pageUrl
  * @return Referer
  */
 public function parse($refererUrl, $pageUrl = null)
 {
     $refererParts = static::parseUrl($refererUrl);
     if (!$refererParts) {
         return Referer::createInvalid();
     }
     $pageUrlParts = static::parseUrl($pageUrl);
     if ($pageUrlParts && $pageUrlParts['host'] === $refererParts['host'] || in_array($refererParts['host'], $this->internalHosts)) {
         return Referer::createInternal();
     }
     $referer = $this->lookup($refererParts['host'], $refererParts['path']);
     if (!$referer) {
         return Referer::createUnknown();
     }
     $searchTerm = null;
     if ($referer['parameters']) {
         parse_str($refererParts['query'], $queryParts);
         foreach ($referer['parameters'] as $parameter) {
             $searchTerm = isset($queryParts[$parameter]) ? $queryParts[$parameter] : $searchTerm;
         }
     }
     return Referer::createKnown($referer['medium'], $referer['source'], $searchTerm);
 }
Example #4
0
 /**
  * Check if the referer is knwon.
  *
  * @return mixed
  */
 public function isKnown()
 {
     return $this->referer->isKnown();
 }