Piwik\Tracker\GoalManager::recordGoals PHP Method

recordGoals() public method

Records one or several goals matched in this request.
public recordGoals ( Piwik\Tracker\Visit\VisitProperties $visitProperties, Request $request )
$visitProperties Piwik\Tracker\Visit\VisitProperties
$request Request
    public function recordGoals(VisitProperties $visitProperties, Request $request)
    {
        $visitorInformation = $visitProperties->getProperties();
        $visitCustomVariables = $request->getMetadata('CustomVariables', 'visitCustomVariables') ?: array();
        /** @var Action $action */
        $action = $request->getMetadata('Actions', 'action');
        $goal = $this->getGoalFromVisitor($visitProperties, $request, $action);
        // Copy Custom Variables from Visit row to the Goal conversion
        // Otherwise, set the Custom Variables found in the cookie sent with this request
        $goal += $visitCustomVariables;
        $maxCustomVariables = CustomVariables::getNumUsableCustomVariables();
        for ($i = 1; $i <= $maxCustomVariables; $i++) {
            if (isset($visitorInformation['custom_var_k' . $i]) && strlen($visitorInformation['custom_var_k' . $i])) {
                $goal['custom_var_k' . $i] = $visitorInformation['custom_var_k' . $i];
            }
            if (isset($visitorInformation['custom_var_v' . $i]) && strlen($visitorInformation['custom_var_v' . $i])) {
                $goal['custom_var_v' . $i] = $visitorInformation['custom_var_v' . $i];
            }
        }
        // some goals are converted, so must be ecommerce Order or Cart Update
        $isRequestEcommerce = $request->getMetadata('Ecommerce', 'isRequestEcommerce');
        if ($isRequestEcommerce) {
            $this->recordEcommerceGoal($visitProperties, $request, $goal, $action);
        } else {
            $this->recordStandardGoals($visitProperties, $request, $goal, $action);
        }
    }

Usage Example

コード例 #1
0
 public function recordLogs(VisitProperties $visitProperties, Request $request)
 {
     // record the goals if there were conversions in this request (even if the visit itself was not converted)
     $goalsConverted = $request->getMetadata('Goals', 'goalsConverted');
     if (!empty($goalsConverted)) {
         $this->goalManager->recordGoals($visitProperties, $request);
     }
 }
All Usage Examples Of Piwik\Tracker\GoalManager::recordGoals