@julienmoumne opened this issue on March 5th 2013

## Context

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() - Metadata now returns 12 metrics : nb_visits, visits_evolution, nb_actions, actions_evolution, revenue, revenue_evolution, nb_conversions, nb_conversions_evolution, orders, orders_evolution, ecommerce_revenue, ecommerce_revenue_evolution

## 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 :

$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.

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.

@julienmoumne commented on March 5th 2013

typo

@mattab commented on March 11th 2013

An alternate workaround would be to include e-commerce metrics only if the Piwik instance has at least one e-commerce site.

This would be a great workaround indeed!

Powered by GitHub Issue Mirror