Piwik\Tracker\GoalManager::detectGoalMatch PHP Method

detectGoalMatch() public method

Detects if an Action matches a given goal. If it does, the URL that triggered the goal is returned. Otherwise null is returned.
public detectGoalMatch ( array $goal, Action $action ) : if
$goal array
$action Action
return if a goal is matched, a string of the Action URL is returned, or if no goal was matched it returns 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
                $actionToMatch = $action->getActionName();
                break;
            case 'event_action':
                $actionToMatch = $action->getEventAction();
                break;
            case 'event_name':
                $actionToMatch = $action->getEventName();
                break;
            case 'event_category':
                $actionToMatch = $action->getEventCategory();
                break;
                // url, external_website, file, manually...
            // url, external_website, file, manually...
            default:
                $actionToMatch = $action->getActionUrlRaw();
                break;
        }
        $pattern_type = $goal['pattern_type'];
        $match = $this->isUrlMatchingGoal($goal, $pattern_type, $actionToMatch);
        if (!$match) {
            return null;
        }
        return $action->getActionUrl();
    }