Piwik\Tracker\GoalManager::detectGoalsMatchingUrl PHP Method

detectGoalsMatchingUrl() public method

Look at the URL or Page Title and sees if it matches any existing Goal definition
public detectGoalsMatchingUrl ( integer $idSite, Action $action ) : array[]
$idSite integer
$action Action
return array[] Goals matched
    public function detectGoalsMatchingUrl($idSite, $action)
    {
        if (!Common::isGoalPluginEnabled()) {
            return array();
        }
        $goals = $this->getGoalDefinitions($idSite);
        $convertedGoals = array();
        foreach ($goals as $goal) {
            $convertedUrl = $this->detectGoalMatch($goal, $action);
            if (!is_null($convertedUrl)) {
                $convertedGoals[] = array('url' => $convertedUrl) + $goal;
            }
        }
        return $convertedGoals;
    }

Usage Example

コード例 #1
0
 public function afterRequestProcessed(VisitProperties $visitProperties, Request $request)
 {
     $goalsConverted = $request->getMetadata('Goals', 'goalsConverted');
     /** @var Action $action */
     $action = $request->getMetadata('Actions', 'action');
     // if the visit hasn't already been converted another way (ie, manual goal conversion or ecommerce conversion,
     // try to convert based on the action)
     if (empty($goalsConverted) && $action) {
         $goalsConverted = $this->goalManager->detectGoalsMatchingUrl($request->getIdSite(), $action);
         $existingGoalsConverted = $request->getMetadata('Goals', 'goalsConverted') ?: array();
         $request->setMetadata('Goals', 'goalsConverted', array_merge($existingGoalsConverted, $goalsConverted));
         if (!empty($goalsConverted)) {
             $request->setMetadata('Goals', 'visitIsConverted', true);
         }
     }
     // There is an edge case when:
     // - two manual goal conversions happen in the same second
     // - which result in handleExistingVisit throwing the exception
     //   because the UPDATE didn't affect any rows (one row was found, but not updated since no field changed)
     // - the exception is caught here and will result in a new visit incorrectly
     // In this case, we cancel the current conversion to be recorded:
     $isManualGoalConversion = $this->isManualGoalConversion($request);
     $requestIsEcommerce = $request->getMetadata('Goals', 'isRequestEcommerce');
     $visitorNotFoundInDb = $request->getMetadata('CoreHome', 'visitorNotFoundInDb');
     if ($visitorNotFoundInDb && ($isManualGoalConversion || $requestIsEcommerce)) {
         $request->setMetadata('Goals', 'goalsConverted', array());
         $request->setMetadata('Goals', 'visitIsConverted', false);
     }
 }
All Usage Examples Of Piwik\Tracker\GoalManager::detectGoalsMatchingUrl