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')
          || self::isEventMatchingGoal($goal) && $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...
            default:
                $actionToMatch = $action->getActionUrlRaw();
                break;
        }

        $pattern_type = $goal['pattern_type'];

        $match = $this->isUrlMatchingGoal($goal, $pattern_type, $actionToMatch);
        if (!$match) {
            return null;
        }

        return $action->getActionUrl();
    }