Skip to content

Commit

Permalink
Expose goal sum metrics added to reports via EnrichRecordWithGoalMetr…
Browse files Browse the repository at this point in the history
…icSums to report metadata.
  • Loading branch information
diosmosis committed Jun 1, 2024
1 parent 25cffc3 commit d5f969c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions plugins/Goals/Goals.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ public function getReportMetadataEnd(&$reports, $info)

$reportsWithGoals = self::getAllReportsWithGoalMetrics();

$conversionDocsTranslation = Piwik::translate('Goals_ColumnConversionSumDocumentation');
$revenueDocsTranslation = Piwik::translate('Goals_ColumnRevenueSumDocumentation');

foreach ($reportsWithGoals as $reportWithGoals) {
$goalMetricsToUse = $goalMetrics;
$goalProcessedMetricsToUse = $goalProcessedMetrics;
Expand All @@ -383,6 +386,16 @@ public function getReportMetadataEnd(&$reports, $info)
&& $apiReportToUpdate['action'] == $reportWithGoals['action']
&& empty($apiReportToUpdate['parameters'])
) {
// add overall Goal metrics computed during archiving by EnrichRecordWithGoalMetricSums
$apiReportToUpdate['metrics']['nb_conversions'] = $goalMetrics['nb_conversions'];
$apiReportToUpdate['metrics']['revenue'] = $goalMetrics['revenue'];

$apiReportToUpdate['metricsDocumentation']['nb_conversions'] = $conversionDocsTranslation;
$apiReportToUpdate['metricsDocumentation']['revenue'] = $revenueDocsTranslation;

$apiReportToUpdate['metricTypes']['nb_conversions'] = Dimension::TYPE_NUMBER;
$apiReportToUpdate['metricTypes']['revenue'] = Dimension::TYPE_MONEY;

$apiReportToUpdate['metricsGoal'] = $goalMetricsToUse;
$apiReportToUpdate['processedMetricsGoal'] = $goalProcessedMetricsToUse;
$apiReportToUpdate['metricTypesGoal'] = $goalMetricTypesToUse;
Expand Down
2 changes: 2 additions & 0 deletions plugins/Goals/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
"ColumnConversions": "Conversions",
"Conversion": "Conversion",
"ColumnConversionsDocumentation": "The number of conversions for %s.",
"ColumnConversionSumDocumentation": "The total number of conversions for all goals.",
"ColumnOrdersDocumentation": "The total number of Ecommerce orders which contained this %s at least once.",
"ColumnPurchasedProductsDocumentation": "The number of purchased products is the sum of Product quantities sold in all Ecommerce orders.",
"ColumnQuantityDocumentation": "Quantity is the total number of products sold for each %s.",
"ColumnRevenueDocumentation": "The total revenue generated by %s.",
"ColumnRevenueSumDocumentation": "The total revenue generated for all goals.",
"ColumnRevenuePerVisitDocumentation": "The total revenue generated by %s divided by the number of visits.",
"ColumnRevenuePerEntryDocumentation": "The total revenue generated by %s divided by the number of entrances.",
"ColumnVisits": "The total number of visits, regardless of whether a goal was triggered or not.",
Expand Down

0 comments on commit d5f969c

Please sign in to comment.