diff --git a/core/API/DataTableManipulator/ReportTotalsCalculator.php b/core/API/DataTableManipulator/ReportTotalsCalculator.php index 17db1bdee7067f4e217939bdc94356f6fc2dc507..b6b82effad2d7564c66da0df5679dd4fbfd74aa7 100644 --- a/core/API/DataTableManipulator/ReportTotalsCalculator.php +++ b/core/API/DataTableManipulator/ReportTotalsCalculator.php @@ -55,7 +55,7 @@ class ReportTotalsCalculator extends DataTableManipulator { $report = $this->findCurrentReport(); - if (!empty($report) && !$report->getDimension()) { + if (!empty($report) && !$report->getDimension() && !$this->isReportAllMetricsReport($report)) { // we currently do not calculate the total value for reports having no dimension return $dataTable; } @@ -215,4 +215,9 @@ class ReportTotalsCalculator extends DataTableManipulator } return null; } + + private function isReportAllMetricsReport(Report $report) + { + return $report->getModule() == 'API' && $report->getAction() == 'get'; + } } diff --git a/core/Plugin/Report.php b/core/Plugin/Report.php index 7cb42e35d4a01eff90053119fad8397818b71b5e..f9604c2040040066e581a98b53110180f7e6505a 100644 --- a/core/Plugin/Report.php +++ b/core/Plugin/Report.php @@ -196,6 +196,7 @@ class Report 'General_Visitors', 'DevicesDetection_DevicesDetection', 'UserSettings_VisitorSettings', + 'API' ); /** diff --git a/plugins/API/API.php b/plugins/API/API.php index e7470b2ab0c45e7070f923580d9358f900e70b7a..85f7c1f9d287908f0c482ef766e15fad5885714e 100644 --- a/plugins/API/API.php +++ b/plugins/API/API.php @@ -440,16 +440,18 @@ class API extends \Piwik\Plugin\API return; } + $firstRow2 = $table2->getFirstRow(); + if (!($firstRow2 instanceof Row)) { + return; + } + $firstRow1 = $table1->getFirstRow(); if (empty($firstRow1)) { $firstRow1 = $table1->addRow(new Row()); } - $firstRow2 = $table2->getFirstRow(); - if ($firstRow2 instanceof Row) { - foreach ($firstRow2->getColumns() as $metric => $value) { - $firstRow1->setColumn($metric, $value); - } + foreach ($firstRow2->getColumns() as $metric => $value) { + $firstRow1->setColumn($metric, $value); } } diff --git a/plugins/API/Reports/Get.php b/plugins/API/Reports/Get.php index d8e7dbbba8634cb4fb16283d98445923622aca7f..11a4df5d6a595b06406f001202b2c01d583c204a 100644 --- a/plugins/API/Reports/Get.php +++ b/plugins/API/Reports/Get.php @@ -26,6 +26,9 @@ class Get extends Report $this->reportsToMerge = $this->getReportsToMerge(); + $this->module = 'API'; + $this->action = 'get'; + $this->category = 'API'; $this->name = Piwik::translate('General_MainMetrics'); $this->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 af5e6a1ade2911825693bfa4b4a658418b406895..2956645547bd8f6a7933d98d074aff093bdba193 100644 --- a/tests/PHPUnit/System/expected/test_apiGetReportMetadata__API.getReportMetadata_day.xml +++ b/tests/PHPUnit/System/expected/test_apiGetReportMetadata__API.getReportMetadata_day.xml @@ -1,68 +1,5 @@ <?xml version="1.0" encoding="utf-8" ?> <result> - <row> - <category>API</category> - <name>Main metrics</name> - <module>API</module> - <action>get</action> - <metrics> - <nb_pageviews>Pageviews</nb_pageviews> - <nb_uniq_pageviews>Unique Pageviews</nb_uniq_pageviews> - <nb_downloads>Downloads</nb_downloads> - <nb_uniq_downloads>Unique Downloads</nb_uniq_downloads> - <nb_outlinks>Outlinks</nb_outlinks> - <nb_uniq_outlinks>Unique Outlinks</nb_uniq_outlinks> - <nb_searches>Searches</nb_searches> - <nb_keywords>Unique Keywords</nb_keywords> - <nb_conversions>Conversions</nb_conversions> - <nb_visits_converted>Visits with Conversions</nb_visits_converted> - <conversion_rate>Conversion Rate</conversion_rate> - <revenue>Revenue</revenue> - <nb_visits_returning>Returning Visits</nb_visits_returning> - <nb_actions_returning>Actions by Returning Visits</nb_actions_returning> - <nb_uniq_visitors_returning>Unique returning visitors</nb_uniq_visitors_returning> - <sum_visit_length_returning>Total time spent by returning visitors (in seconds)</sum_visit_length_returning> - <nb_users_returning>Returning Users</nb_users_returning> - <nb_visits_converted_returning>Number of converted returning visits</nb_visits_converted_returning> - <max_actions_returning>Maximum actions in one returning visit</max_actions_returning> - <nb_uniq_visitors>Unique visitors</nb_uniq_visitors> - <nb_visits>Visits</nb_visits> - <nb_users>Users</nb_users> - <nb_actions>Actions</nb_actions> - <max_actions>Maximum actions in one visit</max_actions> - </metrics> - <metricsDocumentation> - <nb_pageviews>The number of times this page was visited.</nb_pageviews> - <nb_uniq_pageviews>The number of visits that included this page. If a page was viewed multiple times during one visit, it is only counted once.</nb_uniq_pageviews> - <nb_downloads>The number of times this link was clicked.</nb_downloads> - <nb_uniq_downloads>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_downloads> - <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> - <conversion_rate>The percentage of visits that triggered a goal conversion.</conversion_rate> - <nb_uniq_visitors>The number of unduplicated visitors coming to your website. Every user is only counted once, even if he visits the website multiple times a day.</nb_uniq_visitors> - <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> - <avg_order_revenue>Average Order Value</avg_order_revenue> - <avg_time_on_site_returning>Avg. Duration of a Returning Visit (in sec)</avg_time_on_site_returning> - <nb_actions_per_visit_returning>Avg. Actions per Returning Visit</nb_actions_per_visit_returning> - <bounce_rate_returning>Bounce Rate for Returning Visits</bounce_rate_returning> - <bounce_rate>Bounce Rate</bounce_rate> - <nb_actions_per_visit>Actions per Visit</nb_actions_per_visit> - <avg_time_on_site>Avg. Visit Duration (in seconds)</avg_time_on_site> - </processedMetrics> - <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=API&apiAction=get&period=day&date=2008-12-06,2009-01-04</imageGraphUrl> - <imageGraphEvolutionUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=API&apiAction=get&period=day&date=2008-12-06,2009-01-04</imageGraphEvolutionUrl> - <uniqueId>API_get</uniqueId> - </row> <row> <category>All Websites</category> <name>All Websites dashboard</name> @@ -550,6 +487,69 @@ <imageGraphEvolutionUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=UserSettings&apiAction=getLanguageCode&period=day&date=2008-12-06,2009-01-04</imageGraphEvolutionUrl> <uniqueId>UserSettings_getLanguageCode</uniqueId> </row> + <row> + <category>API</category> + <name>Main metrics</name> + <module>API</module> + <action>get</action> + <metrics> + <nb_pageviews>Pageviews</nb_pageviews> + <nb_uniq_pageviews>Unique Pageviews</nb_uniq_pageviews> + <nb_downloads>Downloads</nb_downloads> + <nb_uniq_downloads>Unique Downloads</nb_uniq_downloads> + <nb_outlinks>Outlinks</nb_outlinks> + <nb_uniq_outlinks>Unique Outlinks</nb_uniq_outlinks> + <nb_searches>Searches</nb_searches> + <nb_keywords>Unique Keywords</nb_keywords> + <nb_conversions>Conversions</nb_conversions> + <nb_visits_converted>Visits with Conversions</nb_visits_converted> + <conversion_rate>Conversion Rate</conversion_rate> + <revenue>Revenue</revenue> + <nb_visits_returning>Returning Visits</nb_visits_returning> + <nb_actions_returning>Actions by Returning Visits</nb_actions_returning> + <nb_uniq_visitors_returning>Unique returning visitors</nb_uniq_visitors_returning> + <sum_visit_length_returning>Total time spent by returning visitors (in seconds)</sum_visit_length_returning> + <nb_users_returning>Returning Users</nb_users_returning> + <nb_visits_converted_returning>Number of converted returning visits</nb_visits_converted_returning> + <max_actions_returning>Maximum actions in one returning visit</max_actions_returning> + <nb_uniq_visitors>Unique visitors</nb_uniq_visitors> + <nb_visits>Visits</nb_visits> + <nb_users>Users</nb_users> + <nb_actions>Actions</nb_actions> + <max_actions>Maximum actions in one visit</max_actions> + </metrics> + <metricsDocumentation> + <nb_pageviews>The number of times this page was visited.</nb_pageviews> + <nb_uniq_pageviews>The number of visits that included this page. If a page was viewed multiple times during one visit, it is only counted once.</nb_uniq_pageviews> + <nb_downloads>The number of times this link was clicked.</nb_downloads> + <nb_uniq_downloads>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_downloads> + <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> + <conversion_rate>The percentage of visits that triggered a goal conversion.</conversion_rate> + <nb_uniq_visitors>The number of unduplicated visitors coming to your website. Every user is only counted once, even if he visits the website multiple times a day.</nb_uniq_visitors> + <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> + <avg_order_revenue>Average Order Value</avg_order_revenue> + <avg_time_on_site_returning>Avg. Duration of a Returning Visit (in sec)</avg_time_on_site_returning> + <nb_actions_per_visit_returning>Avg. Actions per Returning Visit</nb_actions_per_visit_returning> + <bounce_rate_returning>Bounce Rate for Returning Visits</bounce_rate_returning> + <bounce_rate>Bounce Rate</bounce_rate> + <nb_actions_per_visit>Actions per Visit</nb_actions_per_visit> + <avg_time_on_site>Avg. Visit Duration (in seconds)</avg_time_on_site> + </processedMetrics> + <imageGraphUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=API&apiAction=get&period=day&date=2008-12-06,2009-01-04</imageGraphUrl> + <imageGraphEvolutionUrl>index.php?module=API&method=ImageGraph.get&idSite=1&apiModule=API&apiAction=get&period=day&date=2008-12-06,2009-01-04</imageGraphEvolutionUrl> + <uniqueId>API_get</uniqueId> + </row> <row> <category>Ecommerce</category> <name>Ecommerce Orders</name>