Piwik\Plugins\Goals\API::addGoal PHP Méthode

addGoal() public méthode

Creates a Goal for a given website.
public addGoal ( integer $idSite, string $name, string $matchAttribute, string $pattern, string $patternType, boolean $caseSensitive = false, boolean | float $revenue = false, boolean $allowMultipleConversionsPerVisit = false, string $description = '' ) : integer
$idSite integer
$name string
$matchAttribute string 'url', 'title', 'file', 'external_website', 'manually', 'event_action', 'event_category' or 'event_name'
$pattern string eg. purchase-confirmation.htm
$patternType string 'regex', 'contains', 'exact'
$caseSensitive boolean
$revenue boolean | float If set, default revenue to assign to conversions
$allowMultipleConversionsPerVisit boolean By default, multiple conversions in the same visit will only record the first conversion. If set to true, multiple conversions will all be recorded within a visit (useful for Ecommerce goals)
$description string
Résultat integer ID of the new goal
    public function addGoal($idSite, $name, $matchAttribute, $pattern, $patternType, $caseSensitive = false, $revenue = false, $allowMultipleConversionsPerVisit = false, $description = '')
    {
        Piwik::checkUserHasAdminAccess($idSite);
        $this->checkPatternIsValid($patternType, $pattern, $matchAttribute);
        $name = $this->checkName($name);
        $pattern = $this->checkPattern($pattern);
        $description = $this->checkDescription($description);
        $revenue = Common::forceDotAsSeparatorForDecimalPoint((double) $revenue);
        $goal = array('name' => $name, 'description' => $description, 'match_attribute' => $matchAttribute, 'pattern' => $pattern, 'pattern_type' => $patternType, 'case_sensitive' => (int) $caseSensitive, 'allow_multiple' => (int) $allowMultipleConversionsPerVisit, 'revenue' => $revenue, 'deleted' => 0);
        $idGoal = $this->getModel()->createGoalForSite($idSite, $goal);
        $this->getGoalsInfoStaticCache()->delete(self::getCacheId($idSite));
        Cache::regenerateCacheWebsiteAttributes($idSite);
        return $idGoal;
    }

Usage Example

Exemple #1
0
 private function createAnyGoal()
 {
     return $this->api->addGoal($this->idSite, 'MyName1', 'event_action', 'test', 'exact');
 }