示例#1
0
 /**
  * Look at the URL or Page Title and sees if it matches any existing Goal definition
  *
  * @param int $idSite
  * @param Action $action
  * @throws Exception
  * @return int Number of goals matched
  */
 public function detectGoalsMatchingUrl($idSite, $action)
 {
     if (!Common::isGoalPluginEnabled()) {
         return false;
     }
     $actionType = $action->getActionType();
     $goals = $this->getGoalDefinitions($idSite);
     foreach ($goals as $goal) {
         $attribute = $goal['match_attribute'];
         // if the attribute to match is not the type of the current action
         if (($attribute == 'url' || $attribute == 'title') && $actionType != Action::TYPE_PAGE_URL || $attribute == 'file' && $actionType != Action::TYPE_DOWNLOAD || $attribute == 'external_website' && $actionType != Action::TYPE_OUTLINK || $attribute == 'manually' || in_array($attribute, array('event_action', 'event_name', 'event_category')) && $actionType != Action::TYPE_EVENT) {
             continue;
         }
         switch ($attribute) {
             case 'title':
                 // Matching on Page Title
                 $url = $action->getActionName();
                 break;
             case 'event_action':
                 $url = $action->getEventAction();
                 break;
             case 'event_name':
                 $url = $action->getEventName();
                 break;
             case 'event_category':
                 $url = $action->getEventCategory();
                 break;
                 // url, external_website, file, manually...
             // url, external_website, file, manually...
             default:
                 $url = $action->getActionUrlRaw();
                 break;
         }
         $pattern_type = $goal['pattern_type'];
         $match = $this->isUrlMatchingGoal($goal, $pattern_type, $url);
         if ($match) {
             $goal['url'] = $action->getActionUrl();
             $this->convertedGoals[] = $goal;
         }
     }
     return count($this->convertedGoals) > 0;
 }
示例#2
0
 /**
  * Detects if an Action matches a given goal. If it does, the URL that triggered the goal
  * is returned. Otherwise null is returned.
  *
  * @param array $goal
  * @param Action $action
  * @return string|null
  */
 public function detectGoalMatch($goal, Action $action)
 {
     $actionType = $action->getActionType();
     $attribute = $goal['match_attribute'];
     // if the attribute to match is not the type of the current action
     if (($attribute == 'url' || $attribute == 'title') && $actionType != Action::TYPE_PAGE_URL || $attribute == 'file' && $actionType != Action::TYPE_DOWNLOAD || $attribute == 'external_website' && $actionType != Action::TYPE_OUTLINK || $attribute == 'manually' || in_array($attribute, array('event_action', 'event_name', 'event_category')) && $actionType != Action::TYPE_EVENT) {
         return null;
     }
     switch ($attribute) {
         case 'title':
             // Matching on Page Title
             $url = $action->getActionName();
             break;
         case 'event_action':
             $url = $action->getEventAction();
             break;
         case 'event_name':
             $url = $action->getEventName();
             break;
         case 'event_category':
             $url = $action->getEventCategory();
             break;
             // url, external_website, file, manually...
         // url, external_website, file, manually...
         default:
             $url = $action->getActionUrlRaw();
             break;
     }
     $pattern_type = $goal['pattern_type'];
     $match = $this->isUrlMatchingGoal($goal, $pattern_type, $url);
     if (!$match) {
         return null;
     }
     return $action->getActionUrl();
 }