ConversionDimension
Piwik\Plugin\Dimension\
ConversionDimension
Since Matomo 2.5.0
Defines a new conversion dimension that records any visit related information during tracking.
You can record any visit information by implementing one of the following events:
onEcommerceOrderConversion(), onEcommerceCartUpdateConversion() or onGoalConversion().
By defining a $columnName and $columnType a new column will be created in the database
(table log_conversion) automatically and the values you return in the previous mentioned events will be saved in
this column.
You can create a new dimension using the console command ./console generate:dimension.
Properties
This abstract class defines the following properties:
$columnNameash; This will be the name of the column in the database table if a $columnType is specified. Inherited fromDimension$columnTypeash; If a columnType is defined, we will create a column in the MySQL table having this type. Inherited fromDimension$typeash; Defines what kind of data type this dimension holds. Inherited fromDimension$namePluralash; Translation key for name plural Inherited fromDimension$segmentNameash; By defining a segment name a user will be able to filter their visitors by this column. Inherited fromDimension$suggestedValuesCallbackash; Sets a callback which will be executed when user will call for suggested values for segment. Inherited fromDimension$acceptValuesash; Here you should explain which values are accepted/useful for your segment, for example: "1, 2, 3, etc." or "comcast.net, proxad.net, etc.". Inherited fromDimension$sqlSegmentash; Defines to which column in the MySQL database the segment belongs (if one is configured). Inherited fromDimension$sqlFilterash; Interesting when specifying a segment. Inherited fromDimension$sqlFilterValueash; Similar to $sqlFilter you can map a given segment value to another value. Inherited fromDimension$allowAnonymousash; Defines whether this dimension (and segment based on this dimension) is available to anonymous users. Inherited fromDimension$dbTableNameash; The name of the database table this dimension refers to Inherited fromDimension$metricIdash; By default the metricId is automatically generated based on the dimensionId. Inherited fromDimension
$columnName
This will be the name of the column in the database table if a $columnType is specified.
Signature
- It is a
stringvalue.
$columnType
If a columnType is defined, we will create a column in the MySQL table having this type. Please make sure MySQL understands this type. Once you change the column type the Matomo (formerly Piwik) platform will notify the user to perform an update which can sometimes take a long time so be careful when choosing the correct column type.
Signature
- It is a
stringvalue.
$type
Defines what kind of data type this dimension holds. By default the type is auto-detected based on
$columnType but sometimes it may be needed to correct this value. Depending on this type, a dimension will be
formatted differently for example.
Signature
- It is a
stringvalue.
$namePlural
Translation key for name plural
Signature
- It is a
stringvalue.
$segmentName
By defining a segment name a user will be able to filter their visitors by this column. If you do not want to define a segment for this dimension, simply leave the name empty.
Signature
- Its type is not specified.
$suggestedValuesCallback
Sets a callback which will be executed when user will call for suggested values for segment.
Signature
- It is a
callablevalue.
$acceptValues
Here you should explain which values are accepted/useful for your segment, for example: "1, 2, 3, etc." or "comcast.net, proxad.net, etc.". If the value needs any special encoding you should mention this as well. For example "Any URL including protocol. The URL must be URL encoded."
Signature
- It is a
stringvalue.
$sqlSegment
Defines to which column in the MySQL database the segment belongs (if one is configured). Defaults to
$this.dbTableName . '.'. $this.columnName but you can customize it eg like HOUR(log_visit.visit_last_action_time).
Signature
- Its type is not specified.
$sqlFilter
Interesting when specifying a segment. Sometimes you want users to set segment values that differ from the way
they are actually stored. For instance if you want to allow to filter by any URL than you might have to resolve
this URL to an action id. Or a country name maybe has to be mapped to a 2 letter country code. You can do this by
specifying either a callable such as array('Classname', 'methodName') or by passing a closure.
There will be four values passed to the given closure or callable: string $valueToMatch, string $segment
(see setSegment()), string $matchType (eg SegmentExpression::MATCH_EQUAL or any other match constant
of this class) and $segmentName.
If the closure returns NULL, then Matomo assumes the segment sub-string will not match any visitor.
Signature
- It can be one of the following types:
stringClosurecallable
$sqlFilterValue
Similar to $sqlFilter you can map a given segment value to another value. For instance you could map "new" to 0, 'returning' to 1 and any other value to '2'. You can either define a callable or a closure. There will be only one value passed to the closure or callable which contains the value a user has set for this segment.
Signature
- It can be one of the following types:
stringarray
$allowAnonymous
Defines whether this dimension (and segment based on this dimension) is available to anonymous users.
Signature
- It is a
boolvalue.
$dbTableName
The name of the database table this dimension refers to
Signature
- It is a
stringvalue.
$metricId
By default the metricId is automatically generated based on the dimensionId. This might sometimes not be as
readable and quite long. If you want more expressive metric names like nb_visits compared to
nb_corehomevisitid, you can eg set a metricId visit.
Signature
- It is a
stringvalue.
Methods
The abstract class defines the following methods:
getDbColumnJoin()ash; To be implemented when a column references another column Inherited fromDimensiongetDbDiscriminator()Inherited fromDimensiongetEnumColumnValues()ash; To be implemented when a column represents an enum. Inherited fromDimensiongetMetricId()ash; Get the metricId which is used to generate metric names based on this dimension. Inherited fromDimensioninstall()ash; Installs the action dimension in case it is not installed yet. Inherited fromDimensionuninstall()ash; Uninstalls the dimension if a $columnName and columnType is set. Inherited fromDimensiongetCategoryId()ash; Returns the ID of the category (typically a translation key). Inherited fromDimensiongetName()ash; Returns the translated name of this dimension which is typically in singular. Inherited fromDimensiongetNamePlural()ash; Returns a translated name in plural for this dimension. Inherited fromDimensionisAnonymousAllowed()ash; Defines whether an anonymous user is allowed to view this dimension Inherited fromDimensionsetSqlSegment()ash; Sets (overwrites) the SQL segment Inherited fromDimensionsetType()ash; Sets (overwrites the dimension type) Inherited fromDimensiongroupValue()ash; A dimension should group values by using this method. Inherited fromDimensionformatValue()ash; Formats the dimension value. Inherited fromDimensionconfigureSegments()ash; Overwrite this method to configure segments. Inherited fromDimensionconfigureMetrics()ash; Configures metrics for this dimension. Inherited fromDimensiongetSegmentName()ash; Returns the name of the segment that this dimension defines Inherited fromDimensiongetSqlSegment()ash; Returns a sql segment expression for this dimension. Inherited fromDimensiongetDbTableName()ash; Returns the name of the database table this dimension belongs to. Inherited fromDimensiongetId()ash; Returns a unique string ID for this dimension. Inherited fromDimensiongetAllDimensions()ash; Gets an instance of all available visit, action and conversion dimension. Inherited fromDimensiongetDimensions()Inherited fromDimensiongetRemovedDimensions()ash; Returns a list of dimension class names that have been removed from core over time Inherited fromDimensiongetModule()ash; Returns the name of the plugin that contains this Dimension. Inherited fromDimensiongetType()ash; Returns the type of the dimension which defines what kind of value this dimension stores. Inherited fromDimensiononEcommerceOrderConversion()— This event is triggered when an ecommerce order is converted.onEcommerceCartUpdateConversion()— This event is triggered when an ecommerce cart update is converted.onGoalConversion()— This event is triggered when an any custom goal is converted.
getDbColumnJoin()
To be implemented when a column references another column
Signature
- Returns:
Join|null—
getDbDiscriminator()
Signature
- Returns:
Discriminator|null—
getEnumColumnValues()
To be implemented when a column represents an enum.
Signature
- It returns a
arrayvalue.
getMetricId()
Get the metricId which is used to generate metric names based on this dimension.
Signature
- It returns a
stringvalue.
install()
Installs the action dimension in case it is not installed yet. The installation is already implemented based on
the $columnName and $columnType. If you want to perform additional actions beside adding the
column to the database - for instance adding an index - you can overwrite this method. We recommend to call
this parent method to get the minimum required actions and then add further custom actions since this makes sure
the column will be installed correctly. We also recommend to change the default install behavior only if really
needed. FYI: We do not directly execute those alter table statements here as we group them together with several
other alter table statements do execute those changes in one step which results in a faster installation. The
column will be added to the log_link_visit_action MySQL table.
Example:
public function install()
{
$changes = parent::install();
$changes['log_link_visit_action'][] = "ADD INDEX index_idsite_servertime ( idsite, server_time )";
return $changes;
}
Signature
- Returns:
array— An array containing the table name as key and an array of MySQL alter table statements that should be executed on the given table. Example:
array(
'log_link_visit_action' => array("ADD COLUMN `$this->columnName` $this->columnType", "ADD INDEX ...")
);
uninstall()
Uninstalls the dimension if a $columnName and columnType is set. In case you perform any custom actions during install() - for instance adding an index - you should make sure to undo those actions by overwriting this method. Make sure to call this parent method to make sure the uninstallation of the column will be done.
Signature
- It does not return anything or a mixed result.
- It throws one of the following exceptions:
getCategoryId()
Returns the ID of the category (typically a translation key).
Signature
- It returns a
stringvalue.
getName()
Returns the translated name of this dimension which is typically in singular.
Signature
- It returns a
stringvalue.
getNamePlural()
Returns a translated name in plural for this dimension.
Signature
- It returns a
stringvalue.
isAnonymousAllowed()
Defines whether an anonymous user is allowed to view this dimension
Signature
- It returns a
boolvalue.
setSqlSegment()
Sets (overwrites) the SQL segment
Signature
It accepts the following parameter(s):
$segment
It does not return anything or a mixed result.
setType()
Sets (overwrites the dimension type)
Signature
It accepts the following parameter(s):
$type
It does not return anything or a mixed result.
groupValue()
A dimension should group values by using this method. Otherwise the same row may appear several times.
Signature
It accepts the following parameter(s):
$value(mixed) —$idSite(int) —
It returns a
mixedvalue.
formatValue()
Formats the dimension value. By default, the dimension is formatted based on the set dimension type.
Signature
It accepts the following parameter(s):
$value(mixed) —$idSite(int) —$formatter(Formatter) —
It returns a
mixedvalue.
configureSegments()
Overwrite this method to configure segments. To do so just create an instance of a Segment class, configure it and call the addSegment() method. You can add one or more segments for this dimension. Example:
$segment = new Segment();
$segment->setSegment('exitPageUrl');
$segment->setName('Actions_ColumnExitPageURL');
$segment->setCategory('General_Visit');
$segmentsList->addSegment($segment);
Signature
It accepts the following parameter(s):
$segmentsList(SegmentsList) —$dimensionSegmentFactory(DimensionSegmentFactory) —
It does not return anything or a mixed result.
- It throws one of the following exceptions:
configureMetrics()
Configures metrics for this dimension.
For certain dimension types, some metrics will be added automatically.
Signature
It accepts the following parameter(s):
$metricsList(MetricsList) —$dimensionMetricFactory(DimensionMetricFactory) —
It does not return anything or a mixed result.
getSegmentName()
Returns the name of the segment that this dimension defines
Signature
- It returns a
stringvalue.
getSqlSegment()
Returns a sql segment expression for this dimension.
Signature
- It returns a
stringvalue.
getDbTableName()
Returns the name of the database table this dimension belongs to.
Signature
- It returns a
stringvalue.
getId()
Returns a unique string ID for this dimension. The ID is built using the namespaced class name of the dimension, but is modified to be more human readable.
Signature
- Returns:
string— eg,"Referrers.Keywords" - It throws one of the following exceptions:
Exception— if the plugin and simple class name of this instance cannot be determined. This would only happen if the dimension is located in the wrong directory.
getAllDimensions()
Gets an instance of all available visit, action and conversion dimension.
Signature
- It returns a
Dimension[]value.
getDimensions()
Signature
It accepts the following parameter(s):
$plugin(Plugin) —
It does not return anything or a mixed result.
getRemovedDimensions()
Returns a list of dimension class names that have been removed from core over time
Signature
- It returns a
string[]value.
getModule()
Returns the name of the plugin that contains this Dimension.
Signature
- It returns a
stringvalue. - It throws one of the following exceptions:
Exception— if the Dimension is not located within a Plugin module.
getType()
Returns the type of the dimension which defines what kind of value this dimension stores.
Signature
- It returns a
stringvalue.
onEcommerceOrderConversion()
This event is triggered when an ecommerce order is converted. Any returned value will be persist in the database.
Return boolean false if you do not want to change the value in some cases.
Signature
It accepts the following parameter(s):
$request(Piwik\Tracker\Request) —$visitor(Piwik\Tracker\Visitor) —$action(Piwik\Tracker\Action|null) —$goalManager(Piwik\Tracker\GoalManager) —
Returns:
mixed|false—
onEcommerceCartUpdateConversion()
This event is triggered when an ecommerce cart update is converted. Any returned value will be persist in the
database. Return boolean false if you do not want to change the value in some cases.
Signature
It accepts the following parameter(s):
$request(Piwik\Tracker\Request) —$visitor(Piwik\Tracker\Visitor) —$action(Piwik\Tracker\Action|null) —$goalManager(Piwik\Tracker\GoalManager) —
Returns:
mixed|false—
onGoalConversion()
This event is triggered when an any custom goal is converted. Any returned value will be persist in the
database. Return boolean false if you do not want to change the value in some cases.
Signature
It accepts the following parameter(s):
$request(Piwik\Tracker\Request) —$visitor(Piwik\Tracker\Visitor) —$action(Piwik\Tracker\Action|null) —$goalManager(Piwik\Tracker\GoalManager) —
Returns:
mixed|false—