Skip to content

Commit

Permalink
Merge pull request #11274 from piwik/reportTotals
Browse files Browse the repository at this point in the history
Added a new method that allows plugins to define metrics we expect to see percentage values
  • Loading branch information
tsteur committed Jan 30, 2017
2 parents 8382be4 + 79222f7 commit 1d27600
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Expand Up @@ -7,7 +7,8 @@ The Product Changelog at **[piwik.org/changelog](http://piwik.org/changelog)** l
## Piwik 3.0.2

### New APIs
* The JavaScript Tracker now supports CrossDomain tracking. The following tracker methods were added for this: `enableCrossDomainLinking`, `disableCrossDomainLinking`, `isCrossDomainLinkingEnabled`
* The JavaScript Tracker now supports CrossDomain tracking. The following tracker methods were added for this: `enableCrossDomainLinking`, `disableCrossDomainLinking`, `isCrossDomainLinkingEnabled`
* Added a new method `Piwik\Plugin\Report::getMetricNamesToProcessReportTotals()` that lets you define which metrics should show percentages in the table report visualization on hover. If defined, these percentages will be automatically calculated.

## Piwik 3.0.1

Expand Down
7 changes: 7 additions & 0 deletions core/API/DataTableManipulator/ReportTotalsCalculator.php
Expand Up @@ -92,6 +92,13 @@ protected function manipulateDataTable($dataTable)
$metricNames[$metricId] = Metrics::getReadableColumnName($metricId);
}

if (!empty($this->report)) {
$reportMetrics = $this->report->getMetricNamesToProcessReportTotals();
foreach ($reportMetrics as $metricId => $metricName) {
$metricNames[$metricId] = $metricName;
}
}

foreach ($firstLevelTable->getRows() as $row) {
$columns = $row->getColumns();
foreach ($metricNames as $metricId => $metricName) {
Expand Down
14 changes: 14 additions & 0 deletions core/Plugin/Report.php
Expand Up @@ -428,6 +428,20 @@ public function getAllMetrics()
return array_keys(array_merge($this->getMetrics(), $processedMetrics));
}

/**
* Use this method to register metrics to process report totals.
*
* When a metric is registered, it will process the report total values and as a result show percentage values
* in the HTML Table reporting visualization.
*
* @return string[] metricId => metricColumn, if the report has only column names and no IDs, it should return
* metricColumn => metricColumn, eg array('13' => 'nb_pageviews') or array('mymetric' => 'mymetric')
*/
public function getMetricNamesToProcessReportTotals()
{
return array();
}

/**
* Returns an array of metric documentations and their corresponding translations. Eg
* `array('nb_visits' => 'If a visitor comes to your website for the first time or if they visit a page more than 30 minutes after...')`.
Expand Down

0 comments on commit 1d27600

Please sign in to comment.