Empowering People Ethically with the leading open source alternative to Google Analytics that gives you full control over your data. Matomo lets you easily collect data from websites & apps and visualise this data and extract insights. Privacy is built-in. Liberating Web Analytics. Star us on Github? +1. And we love Pull Requests!
The issue described here came-up while updating the MultiSites API to support the development of the MobileMessaging Plugin :
refs #389
new API method to retrieve only one Piwik site : Piwik_MultiSites_API->getOne()
per #2708 description, Piwik_MultiSites_API methods now support a new parameter named enhanced. When activated, Goal Conversions, eCommerce Conversions and eCommerce Revenue along with their evolution will be included in the API output.
API metrics refactored in (@ignored)Piwik_MultiSites_API->getApiMetrics()
MultiSites Plugin Report Metrics are defined in plugins/MultiSites/API.php#L447 :
Ecommerce Orders & Revenue metrics are returned without checking if the Piwik instance has e-commerce enabled.
After reading the second side of this issue, it should become clear, in the context of scheduled reports, that MultiSites.getReportMetadata($notification) can not leverage the value of $notification[$idSites] to determine if e-commerce metrics should be included or excluded in metadata.
2) A scheduled report is necessarily tied to a Site even though it features a multi-site report
The scheduled report plugin was initially developed for mono-site reporting.
A scheduled report is therefore always created for a specific site (ie. the report table has an idsite field).
Later developments included the MultiSites plugin report. The issue described here is not the first one caused by this mismatch.
$notification[$idSites] = site identifier the report was created for
Event though a scheduled report can be created on a non-ecommerce site, the MultiSites report should include e-commerce metrics if the user has permissions to see e-commerce sites.
Context
The issue described here came-up while updating the MultiSites API to support the development of the MobileMessaging Plugin :
Issue Details
The issue is two-sided.
1) Metrics not defined in Metadata are not returned by API.getProcessedReport()
Piwik_API_API::getInstance()->getProcessedReport() is used by scheduled reports to retrieve the list of metrics to display. It also returns their values.
Metrics returned by Piwik_API_API::getInstance()->getProcessedReport() are defined based on the report <metrics/> metadata definition. Metrics not defined in Metadata are filtered-out in handleSimpleDataTable().
MultiSites Plugin Report Metrics are defined in plugins/MultiSites/API.php#L447 : Ecommerce Orders & Revenue metrics are returned without checking if the Piwik instance has e-commerce enabled.
After reading the second side of this issue, it should become clear, in the context of scheduled reports, that MultiSites.getReportMetadata($notification) can not leverage the value of $notification[$idSites] to determine if e-commerce metrics should be included or excluded in metadata.
2) A scheduled report is necessarily tied to a Site even though it features a multi-site report
The scheduled report plugin was initially developed for mono-site reporting.
A scheduled report is therefore always created for a specific site (ie. the report table has an idsite field).
Later developments included the MultiSites plugin report. The issue described here is not the first one caused by this mismatch.
Scheduled reports are generated using Piwik_API_API::getInstance()->getProcessedReport() by supplying the site identifier the report was created for.
The site identifier is then carried-on all the way to each getReportMetadata() plugin method such as MultiSites.getReportMetadata($notification). In effect :
Event though a scheduled report can be created on a non-ecommerce site, the MultiSites report should include e-commerce metrics if the user has permissions to see e-commerce sites.
Therefore, $notification[can not be used in https://github.com/piwik/piwik/blob/master/plugins/MultiSites/MultiSites.php#L41 MultiSites.getReportMetadata($notification) to conditionally include/exclude e-commerce metrics.
Solutions
The currently implemented workaround is to always include e-commerce metrics.
An alternate workaround would be to include e-commerce metrics only if the Piwik instance has at least one e-commerce site.