PHP Class Piwik\Plugins\Goals\API

If you are tracking Ecommerce orders and products on your site, the functions "getItemsSku", "getItemsName" and "getItemsCategory" will return the list of products purchased on your site, either grouped by Product SKU, Product Name or Product Category. For each name, SKU or category, the following metrics are returned: Total revenue, Total quantity, average price, average quantity, number of orders (or abandoned carts) containing this product, number of visits on the Product page, Conversion rate. By default, these functions return the 'Products purchased'. These functions also accept an optional parameter &abandonedCarts=1. If the parameter is set, it will instead return the metrics for products that were left in an abandoned cart therefore not purchased. The API also lets you request overall Goal metrics via the method "get": Conversions, Visits with at least one conversion, Conversion rate and Revenue. If you wish to request specific metrics about Ecommerce goals, you can set the parameter &idGoal=ecommerceAbandonedCart to get metrics about abandoned carts (including Lost revenue, and number of items left in the cart) or &idGoal=ecommerceOrder to get metrics about Ecommerce orders (number of orders, visits with an order, subtotal, tax, shipping, discount, revenue, items ordered) See also the documentation about Tracking Goals in Piwik.
Inheritance: extends Piwik\Plugin\API
Afficher le fichier Open project: piwik/piwik Class Usage Examples

Méthodes publiques

Méthode Description
addGoal ( integer $idSite, string $name, string $matchAttribute, string $pattern, string $patternType, boolean $caseSensitive = false, boolean | float $revenue = false, boolean $allowMultipleConversionsPerVisit = false, string $description = '' ) : integer Creates a Goal for a given website.
deleteGoal ( integer $idSite, integer $idGoal ) : void Soft deletes a given Goal.
get ( integer $idSite, string $period, string $date, boolean $segment = false, boolean | integer $idGoal = false, array $columns = [] ) : DataTable Returns Goals data.
getConversionRate ( $idSite, $period, $date, $segment = false, $idGoal = false )
getConversions ( $idSite, $period, $date, $segment = false, $idGoal = false )
getDaysToConversion ( integer $idSite, string $period, string $date, string | boolean $segment = false, integer | boolean $idGoal = false ) : false | DataTable Gets a DataTable that maps ranges of days to the number of conversions that occurred within those ranges, for the specified site, date range, segment and goal.
getGoal ( integer $idSite, integer $idGoal ) : array Return a single goal.
getGoals ( string | array $idSite ) : array Returns all Goals for a given website, or list of websites
getItemsCategory ( $idSite, $period, $date, $abandonedCarts = false, $segment = false )
getItemsName ( $idSite, $period, $date, $abandonedCarts = false, $segment = false )
getItemsSku ( $idSite, $period, $date, $abandonedCarts = false, $segment = false )
getMetrics ( $idSite, $period, $date, $segment = false, $idGoal = false, $columns = [] ) Similar to {@link get()} but does not return any metrics for new and returning visitors. It won't apply any segment by default. This method is deprecated from the API as it is only there to make the implementation of the actual {@link get()} method easy.
getNbVisitsConverted ( $idSite, $period, $date, $segment = false, $idGoal = false )
getRevenue ( $idSite, $period, $date, $segment = false, $idGoal = false )
getVisitsUntilConversion ( integer $idSite, string $period, string $date, string | boolean $segment = false, integer | boolean $idGoal = false ) : boolean | DataTable Gets a DataTable that maps ranges of visit counts to the number of conversions that occurred on those visits for the specified site, date range, segment and goal.
updateGoal ( integer $idSite, integer $idGoal, $name, $matchAttribute, string $pattern, string $patternType, boolean $caseSensitive = false, boolean | float $revenue = false, boolean $allowMultipleConversionsPerVisit = false, string $description = '' ) : void Updates a Goal description.

Méthodes protégées

Méthode Description
appendSegment ( $segment, $segmentToAppend )
convertSpecialGoalIds ( string | integer $idGoal ) : integer Helper function that checks for special string goal IDs and converts them to their integer equivalents.
enrichItemsDataTableWithItemsViewMetrics ( $dataTable, $idSite, $period, $date, $segment, $idSubtable )
enrichItemsTableWithViewMetrics ( $dataTable, $recordName, $idSite, $period, $date, $segment ) Enhances the dataTable with Items attributes found in the Custom Variables report.
getGoalSpecificDataTable ( string $recordName, integer | string $idSite, string $period, string $date, string $segment, integer | boolean $idGoal ) : false | DataTable Utility method that retrieve an archived DataTable for a specific site, date range, segment and goal. If not goal is specified, this method will retrieve and sum the data for every goal.
getItems ( $recordName, $idSite, $period, $date, $abandonedCarts, $segment ) Returns a datatable of Items SKU/name or categories and their metrics If $abandonedCarts set to 1, will return items abandoned in carts. If set to 0, will return items ordered
getNumeric ( $idSite, $period, $date, $segment, $toFetch )
renameNotDefinedRow ( $dataTable, $notDefinedStringPretty )

Private Methods

Méthode Description
checkDescription ( $description )
checkName ( $name )
checkPattern ( $pattern )
checkPatternIsValid ( $patternType, $pattern, $matchAttribute )
formatGoal ( $goal )
getCacheId ( $idSite )
getGoalsInfoStaticCache ( )
getModel ( )

Method Details

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

appendSegment() protected méthode

protected appendSegment ( $segment, $segmentToAppend )

convertSpecialGoalIds() protected static méthode

Checks for the following values: Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_CART
protected static convertSpecialGoalIds ( string | integer $idGoal ) : integer
$idGoal string | integer The goal id as an integer or a special string.
Résultat integer The numeric goal id.

deleteGoal() public méthode

Stats data in the archives will still be recorded, but not displayed.
public deleteGoal ( integer $idSite, integer $idGoal ) : void
$idSite integer
$idGoal integer
Résultat void

enrichItemsDataTableWithItemsViewMetrics() protected méthode

protected enrichItemsDataTableWithItemsViewMetrics ( $dataTable, $idSite, $period, $date, $segment, $idSubtable )

enrichItemsTableWithViewMetrics() protected méthode

Enhances the dataTable with Items attributes found in the Custom Variables report.
protected enrichItemsTableWithViewMetrics ( $dataTable, $recordName, $idSite, $period, $date, $segment )
$dataTable
$recordName
$idSite
$period
$date
$segment

get() public méthode

Returns Goals data.
public get ( integer $idSite, string $period, string $date, boolean $segment = false, boolean | integer $idGoal = false, array $columns = [] ) : DataTable
$idSite integer
$period string
$date string
$segment boolean
$idGoal boolean | integer
$columns array Array of metrics to fetch: nb_conversions, conversion_rate, revenue
Résultat Piwik\DataTable

getConversionRate() public méthode

public getConversionRate ( $idSite, $period, $date, $segment = false, $idGoal = false )

getConversions() public méthode

public getConversions ( $idSite, $period, $date, $segment = false, $idGoal = false )

getDaysToConversion() public méthode

Gets a DataTable that maps ranges of days to the number of conversions that occurred within those ranges, for the specified site, date range, segment and goal.
public getDaysToConversion ( integer $idSite, string $period, string $date, string | boolean $segment = false, integer | boolean $idGoal = false ) : false | DataTable
$idSite integer The site to select data from.
$period string The period type.
$date string The date type.
$segment string | boolean The segment.
$idGoal integer | boolean The id of the goal to get data for. If this is set to false, data for every goal that belongs to $idSite is returned.
Résultat false | Piwik\DataTable

getGoal() public méthode

Return a single goal.
public getGoal ( integer $idSite, integer $idGoal ) : array
$idSite integer
$idGoal integer
Résultat array An array of goal attributes.

getGoalSpecificDataTable() protected méthode

Utility method that retrieve an archived DataTable for a specific site, date range, segment and goal. If not goal is specified, this method will retrieve and sum the data for every goal.
protected getGoalSpecificDataTable ( string $recordName, integer | string $idSite, string $period, string $date, string $segment, integer | boolean $idGoal ) : false | DataTable
$recordName string The archive entry name.
$idSite integer | string The site(s) to select data for.
$period string The period type.
$date string The date type.
$segment string The segment.
$idGoal integer | boolean The id of the goal to get data for. If this is set to false, data for every goal that belongs to $idSite is returned.
Résultat false | Piwik\DataTable

getGoals() public méthode

Returns all Goals for a given website, or list of websites
public getGoals ( string | array $idSite ) : array
$idSite string | array Array or Comma separated list of website IDs to request the goals for
Résultat array Array of Goal attributes

getItems() protected méthode

Returns a datatable of Items SKU/name or categories and their metrics If $abandonedCarts set to 1, will return items abandoned in carts. If set to 0, will return items ordered
protected getItems ( $recordName, $idSite, $period, $date, $abandonedCarts, $segment )

getItemsCategory() public méthode

public getItemsCategory ( $idSite, $period, $date, $abandonedCarts = false, $segment = false )

getItemsName() public méthode

public getItemsName ( $idSite, $period, $date, $abandonedCarts = false, $segment = false )

getItemsSku() public méthode

public getItemsSku ( $idSite, $period, $date, $abandonedCarts = false, $segment = false )

getMetrics() public méthode

Similar to {@link get()} but does not return any metrics for new and returning visitors. It won't apply any segment by default. This method is deprecated from the API as it is only there to make the implementation of the actual {@link get()} method easy.
Deprecation:
public getMetrics ( $idSite, $period, $date, $segment = false, $idGoal = false, $columns = [] )

getNbVisitsConverted() public méthode

public getNbVisitsConverted ( $idSite, $period, $date, $segment = false, $idGoal = false )

getNumeric() protected méthode

protected getNumeric ( $idSite, $period, $date, $segment, $toFetch )

getRevenue() public méthode

public getRevenue ( $idSite, $period, $date, $segment = false, $idGoal = false )

getVisitsUntilConversion() public méthode

Gets a DataTable that maps ranges of visit counts to the number of conversions that occurred on those visits for the specified site, date range, segment and goal.
public getVisitsUntilConversion ( integer $idSite, string $period, string $date, string | boolean $segment = false, integer | boolean $idGoal = false ) : boolean | DataTable
$idSite integer The site to select data from.
$period string The period type.
$date string The date type.
$segment string | boolean The segment.
$idGoal integer | boolean The id of the goal to get data for. If this is set to false, data for every goal that belongs to $idSite is returned.
Résultat boolean | Piwik\DataTable

renameNotDefinedRow() protected méthode

protected renameNotDefinedRow ( $dataTable, $notDefinedStringPretty )

updateGoal() public méthode

Will not update or re-process the conversions already recorded
See also: addGoal() for parameters description
public updateGoal ( integer $idSite, integer $idGoal, $name, $matchAttribute, string $pattern, string $patternType, boolean $caseSensitive = false, boolean | float $revenue = false, boolean $allowMultipleConversionsPerVisit = false, string $description = '' ) : void
$idSite integer
$idGoal integer
$name
$matchAttribute
$pattern string
$patternType string
$caseSensitive boolean
$revenue boolean | float
$allowMultipleConversionsPerVisit boolean
$description string
Résultat void