private static function getPriority(Action $actionType) { $key = array_search($actionType->getActionType(), self::$factoryPriority); if (false === $key) { return -1; } return $key; }
/** * Detect whether action is an outlink given host aliases * * @param Action $action * @return bool true if the outlink the visitor clicked on points to one of the known hosts for this website */ public static function detectActionIsOutlinkOnAliasHost(Action $action, $idSite) { if ($action->getActionType() != Action::TYPE_OUTLINK) { return false; } $decodedActionUrl = $action->getActionUrl(); $actionUrlParsed = @parse_url($decodedActionUrl); if (!isset($actionUrlParsed['host'])) { return false; } return Visit::isHostKnownAliasHost($actionUrlParsed['host'], $idSite); }
/** * @param Action|null $action * @return bool */ public static function shouldCountInteraction($action) { if (empty($action)) { return false; } $idActionUrl = $action->getIdActionUrlForEntryAndExitIds(); if ($idActionUrl !== false) { return true; } $actionType = $action->getActionType(); $types = array(Action::TYPE_SITE_SEARCH); if (in_array($actionType, $types)) { return true; } return false; }
/** * @param Request $request * @param Visitor $visitor * @param Action|null $action * @return int */ public function onExistingVisit(Request $request, Visitor $visitor, $action) { if (!$action) { return false; } $increment = 'visit_total_actions + 1'; $idActionUrl = $action->getIdActionUrlForEntryAndExitIds(); if ($idActionUrl !== false) { return $increment; } $actionType = $action->getActionType(); if (in_array($actionType, array(Action::TYPE_SITE_SEARCH, Action::TYPE_EVENT))) { return $increment; } return false; }
/** * 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; }
/** * 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 */ function detectGoalsMatchingUrl($idSite, $action) { if (!Common::isGoalPluginEnabled()) { return false; } $decodedActionUrl = $action->getActionUrl(); $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') { continue; } $url = $decodedActionUrl; // Matching on Page Title if ($attribute == 'title') { $url = $action->getActionName(); } $pattern_type = $goal['pattern_type']; $match = $this->isUrlMatchingGoal($goal, $pattern_type, $url); if ($match) { $goal['url'] = $decodedActionUrl; $this->convertedGoals[] = $goal; } } return count($this->convertedGoals) > 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(); }
/** * @param Action|null $action * @return bool */ private function isSiteSearchAction($action) { return $action && $action->getActionType() == Action::TYPE_SITE_SEARCH; }
/** * @param Action|null $action * @return bool */ private function isEventAction($action) { return $action && $action->getActionType() == Action::TYPE_EVENT; }
/** * 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 */ function detectGoalsMatchingUrl($idSite, $action) { if (!Common::isGoalPluginEnabled()) { return false; } $decodedActionUrl = $action->getActionUrl(); $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 ($actionType == Action::TYPE_PAGE_URL && $attribute != 'url' && $attribute != 'title' || $actionType == Action::TYPE_DOWNLOAD && $attribute != 'file' || $actionType == Action::TYPE_OUTLINK && $attribute != 'external_website' || $attribute == 'manually') { continue; } $url = $decodedActionUrl; // Matching on Page Title if ($attribute == 'title') { $url = $action->getActionName(); } $pattern_type = $goal['pattern_type']; switch ($pattern_type) { case 'regex': $pattern = $goal['pattern']; if (strpos($pattern, '/') !== false && strpos($pattern, '\\/') === false) { $pattern = str_replace('/', '\\/', $pattern); } $pattern = '/' . $pattern . '/'; if (!$goal['case_sensitive']) { $pattern .= 'i'; } $match = @preg_match($pattern, $url) == 1; break; case 'contains': if ($goal['case_sensitive']) { $matched = strpos($url, $goal['pattern']); } else { $matched = stripos($url, $goal['pattern']); } $match = $matched !== false; break; case 'exact': if ($goal['case_sensitive']) { $matched = strcmp($goal['pattern'], $url); } else { $matched = strcasecmp($goal['pattern'], $url); } $match = $matched == 0; break; default: throw new Exception(Piwik::translate('General_ExceptionInvalidGoalPattern', array($pattern_type))); break; } if ($match) { $goal['url'] = $decodedActionUrl; $this->convertedGoals[] = $goal; } } return count($this->convertedGoals) > 0; }