Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Giehl <stefan@piwik.org>2018-02-14 21:43:49 +0300
committerGitHub <noreply@github.com>2018-02-14 21:43:49 +0300
commit87498556369e6a7156049b2de1e9b91a82b24aff (patch)
treed3ba3acde18836e5bd020701b473b324b2f7287b /plugins/Actions
parenta3b7afd12708a92886ab9dc48f1fbfd24538d571 (diff)
Allow plugins to define custom action types (#12556)
* Make it possible to define custom action types (for segmentation) * update CHANGELOG * Add data format to be able to detect ids that are used more than once * set fixed value for acceptedValues * fix tests
Diffstat (limited to 'plugins/Actions')
-rw-r--r--plugins/Actions/Actions.php30
-rw-r--r--plugins/Actions/Columns/ActionType.php51
2 files changed, 68 insertions, 13 deletions
diff --git a/plugins/Actions/Actions.php b/plugins/Actions/Actions.php
index 35c673e716..aadadca6ad 100644
--- a/plugins/Actions/Actions.php
+++ b/plugins/Actions/Actions.php
@@ -10,6 +10,7 @@ namespace Piwik\Plugins\Actions;
use Piwik\Site;
use Piwik\Plugin\ViewDataTable;
+use Piwik\Tracker\Action;
/**
* Actions plugin
@@ -32,6 +33,7 @@ class Actions extends \Piwik\Plugin
'Insights.addReportToOverview' => 'addReportToInsightsOverview',
'Metrics.getDefaultMetricTranslations' => 'addMetricTranslations',
'Metrics.getDefaultMetricDocumentationTranslations' => 'addMetricDocumentationTranslations',
+ 'Actions.addActionTypes' => 'addActionTypes'
);
}
@@ -91,6 +93,34 @@ class Actions extends \Piwik\Plugin
$jsFiles[] = "plugins/Actions/javascripts/rowactions.js";
}
+ public function addActionTypes(&$types)
+ {
+ $types[] = [
+ 'id' => Action::TYPE_PAGE_URL,
+ 'name' => 'pageviews'
+ ];
+ $types[] = [
+ 'id' => Action::TYPE_CONTENT,
+ 'name' => 'contents'
+ ];
+ $types[] = [
+ 'id' => Action::TYPE_SITE_SEARCH,
+ 'name' => 'sitesearches'
+ ];
+ $types[] = [
+ 'id' => Action::TYPE_EVENT,
+ 'name' => 'events'
+ ];
+ $types[] = [
+ 'id' => Action::TYPE_OUTLINK,
+ 'name' => 'outlinks'
+ ];
+ $types[] = [
+ 'id' => Action::TYPE_DOWNLOAD,
+ 'name' => 'downloads'
+ ];
+ }
+
public function isSiteSearchEnabled($idSites, $idSite)
{
$idSites = Site::getIdSitesFromIdSitesString($idSites, true);
diff --git a/plugins/Actions/Columns/ActionType.php b/plugins/Actions/Columns/ActionType.php
index c407403588..d2dd02ec4c 100644
--- a/plugins/Actions/Columns/ActionType.php
+++ b/plugins/Actions/Columns/ActionType.php
@@ -10,8 +10,9 @@ namespace Piwik\Plugins\Actions\Columns;
use Piwik\Columns\DimensionMetricFactory;
use Piwik\Columns\MetricsList;
+use Piwik\Development;
+use Piwik\Piwik;
use Piwik\Plugin\Dimension\ActionDimension;
-use Piwik\Tracker\Action;
use Exception;
/**
@@ -21,15 +22,6 @@ use Exception;
*/
class ActionType extends ActionDimension
{
- private $types = array(
- Action::TYPE_PAGE_URL => 'pageviews',
- Action::TYPE_CONTENT => 'contents',
- Action::TYPE_SITE_SEARCH => 'sitesearches',
- Action::TYPE_EVENT => 'events',
- Action::TYPE_OUTLINK => 'outlinks',
- Action::TYPE_DOWNLOAD => 'downloads'
- );
-
protected $columnName = 'type';
protected $dbTableName = 'log_action';
protected $segmentName = 'actionType';
@@ -40,12 +32,45 @@ class ActionType extends ActionDimension
public function __construct()
{
- $this->acceptValues = sprintf('A type of action, such as: %s', implode(', ', $this->types));
+ $this->acceptValues = 'A type of action, such as: pageviews, contents, sitesearches, events, outlinks, downloads';
}
public function getEnumColumnValues()
{
- return $this->types;
+ $availableTypes = [];
+ /**
+ * Triggered to determine the available action types
+ *
+ * Plugin can use this event to add their own action types, so they are available in segmentation
+ * The array maps internal ids to readable action type names used in visitor details
+ *
+ * **Example**
+ *
+ * public function addActionTypes(&$availableTypes)
+ * {
+ * $availableTypes[] = array(
+ * 'id' => 76,
+ * 'name' => 'media_play'
+ * );
+ * }
+ *
+ * @param array $availableTypes
+ */
+ Piwik::postEvent('Actions.addActionTypes', [&$availableTypes]);
+
+ $types = [];
+
+ foreach ($availableTypes as $type) {
+ if (empty($type['id']) || empty($type['name'])) {
+ throw new Exception("Invalid action added with event `Actions.addActionTypes`: " . var_export($type, true));
+ }
+ if (Development::isEnabled() && array_key_exists($type['id'], $types)) {
+ throw new Exception(sprintf("Action '%s' with id %s couldn't be added, as '%s' was already added for this id", $type['name'], $type['id'], $types[$type['id']]));
+ }
+ $types[$type['id']] = $type['name'];
+ }
+
+ return $types;
}
public function configureMetrics(MetricsList $metricsList, DimensionMetricFactory $dimensionMetricFactory)
@@ -53,4 +78,4 @@ class ActionType extends ActionDimension
// do not genereate any metric for this
}
-} \ No newline at end of file
+}