From b0717253476d3b704d127f49985d9f7165f3facc Mon Sep 17 00:00:00 2001 From: diosmosis <benaka@piwik.pro> Date: Thu, 6 Nov 2014 18:15:39 -0800 Subject: [PATCH] Allow processed metrics to provide metric documentation. --- core/Plugin/Metric.php | 8 ++++++++ core/Plugin/Report.php | 17 +++++++++++++++++ ...eportMetadata__API.getReportMetadata_day.xml | 12 ++++++++++++ 3 files changed, 37 insertions(+) diff --git a/core/Plugin/Metric.php b/core/Plugin/Metric.php index 7a6033e8b7..2c4410c548 100644 --- a/core/Plugin/Metric.php +++ b/core/Plugin/Metric.php @@ -52,6 +52,14 @@ abstract class Metric */ abstract public function getTranslatedName(); + /** + * TODO + */ + public function getDocumentation() + { + return ""; + } + /** * TODO */ diff --git a/core/Plugin/Report.php b/core/Plugin/Report.php index e5c862cf32..21e6058606 100644 --- a/core/Plugin/Report.php +++ b/core/Plugin/Report.php @@ -428,6 +428,23 @@ class Report } } + $processedMetrics = $this->processedMetrics ?: array(); + foreach ($processedMetrics as $processedMetric) { + if (!($processedMetric instanceof ProcessedMetric)) { + continue; + } + + $name = $processedMetric->getName(); + $metricDocs = $processedMetric->getDocumentation(); + if (empty($metricDocs)) { + $metricDocs = @$translations[$name]; + } + + if (!empty($metricDocs)) { + $documentation[$processedMetric->getName()] = $metricDocs; + } + } + return $documentation; } diff --git a/tests/PHPUnit/System/expected/test_apiGetReportMetadata__API.getReportMetadata_day.xml b/tests/PHPUnit/System/expected/test_apiGetReportMetadata__API.getReportMetadata_day.xml index f4739f52cb..e4f13e2e83 100644 --- a/tests/PHPUnit/System/expected/test_apiGetReportMetadata__API.getReportMetadata_day.xml +++ b/tests/PHPUnit/System/expected/test_apiGetReportMetadata__API.getReportMetadata_day.xml @@ -44,6 +44,10 @@ <nb_visits>If a visitor comes to your website for the first time or if he visits a page more than 30 minutes after his last page view, this will be recorded as a new visit.</nb_visits> <nb_users>The number of users logged in your website. It is the number of unique active users that have a User ID set (via the Tracking code function 'setUserId').</nb_users> <nb_actions>The number of actions performed by your visitors. Actions can be page views, internal site searches, downloads or outlinks.</nb_actions> + <avg_time_generation>The average time it took to generate the page. This metric includes the time it took the server to generate the web page, plus the time it took for the visitor to download the response from the server. A lower 'Avg. generation time' means a faster website for your visitors!</avg_time_generation> + <bounce_rate>The percentage of visits that only had a single pageview. This means, that the visitor left the website directly from the entrance page.</bounce_rate> + <nb_actions_per_visit>The average number of actions (page views, site searches, downloads or outlinks) that were performed during the visits.</nb_actions_per_visit> + <avg_time_on_site>The average duration of a visit.</avg_time_on_site> </metricsDocumentation> <processedMetrics> <avg_time_generation>Avg. generation time</avg_time_generation> @@ -137,6 +141,9 @@ <nb_visits>If a visitor comes to your website for the first time or if he visits a page more than 30 minutes after his last page view, this will be recorded as a new visit.</nb_visits> <nb_users>The number of users logged in your website. It is the number of unique active users that have a User ID set (via the Tracking code function 'setUserId').</nb_users> <nb_actions>The number of actions performed by your visitors. Actions can be page views, internal site searches, downloads or outlinks.</nb_actions> + <bounce_rate>The percentage of visits that only had a single pageview. This means, that the visitor left the website directly from the entrance page.</bounce_rate> + <nb_actions_per_visit>The average number of actions (page views, site searches, downloads or outlinks) that were performed during the visits.</nb_actions_per_visit> + <avg_time_on_site>The average duration of a visit.</avg_time_on_site> </metricsDocumentation> <processedMetrics> <bounce_rate>Bounce Rate</bounce_rate> @@ -732,6 +739,7 @@ <nb_outlinks>The number of times this link was clicked.</nb_outlinks> <nb_uniq_outlinks>The number of visits that involved a click on this link. If a link was clicked multiple times during one visit, it is only counted once.</nb_uniq_outlinks> <nb_searches>The number of visits that searched for this keyword on your website's search engine.</nb_searches> + <avg_time_generation>The average time it took to generate the page. This metric includes the time it took the server to generate the web page, plus the time it took for the visitor to download the response from the server. A lower 'Avg. generation time' means a faster website for your visitors!</avg_time_generation> </metricsDocumentation> <processedMetrics> <avg_time_generation>Avg. generation time</avg_time_generation> @@ -2168,6 +2176,10 @@ <nb_visits>If a visitor comes to your website for the first time or if he visits a page more than 30 minutes after his last page view, this will be recorded as a new visit.</nb_visits> <nb_users>The number of users logged in your website. It is the number of unique active users that have a User ID set (via the Tracking code function 'setUserId').</nb_users> <nb_actions>The number of actions performed by your visitors. Actions can be page views, internal site searches, downloads or outlinks.</nb_actions> + <avg_time_generation>The average time it took to generate the page. This metric includes the time it took the server to generate the web page, plus the time it took for the visitor to download the response from the server. A lower 'Avg. generation time' means a faster website for your visitors!</avg_time_generation> + <bounce_rate>The percentage of visits that only had a single pageview. This means, that the visitor left the website directly from the entrance page.</bounce_rate> + <nb_actions_per_visit>The average number of actions (page views, site searches, downloads or outlinks) that were performed during the visits.</nb_actions_per_visit> + <avg_time_on_site>The average duration of a visit.</avg_time_on_site> </metricsDocumentation> <uniqueId>API_get</uniqueId> </row> -- GitLab