Skip to content

Commit

Permalink
allow reports to specify that they have goal specific metrics (for so…
Browse files Browse the repository at this point in the history
…me or all goals), but not the overall goal sum metrics provided by EnrichRecordWithGoalMetricSums
  • Loading branch information
diosmosis committed Jun 3, 2024
1 parent 6cf6e7d commit b4d1125
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
22 changes: 22 additions & 0 deletions core/Plugin/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ class Report
*/
protected $hasGoalMetrics = false;

/**
* Set this property to true if your report supports goal metrics, but does not also include overall summed goal
* metrics (total conversions and total revenue across all goals).
*
* By default, Matomo assumes reports that set {@see self::$hasGoalMetrics} to `true` provide these overall
* metrics, but some reports are not able to compute them.
*
* Only used if {@see self::$hasGoalMetrics} is true.
* @var bool
* @api
*/
protected $hasGoalSumMetrics = true;

/**
* Set this property to false in case your report can't/shouldn't be flattened.
* In this case, flattener won't be applied even if parameter is provided in a request
Expand Down Expand Up @@ -593,6 +606,15 @@ public function hasGoalMetrics()
return $this->hasGoalMetrics;
}

/**
* @return bool
* @ignore
*/
public function hasGoalSumMetrics()
{
return $this->hasGoalSumMetrics;
}

/**
* @return bool
* @ignore
Expand Down
1 change: 1 addition & 0 deletions plugins/Actions/Reports/GetEntryPageTitles.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protected function init()
$this->actionToLoadSubTables = $this->action;
$this->subcategoryId = 'Actions_SubmenuPagesEntry';
$this->hasGoalMetrics = true;
$this->hasGoalSumMetrics = false;
}

public function configureWidgets(WidgetsList $widgetsList, ReportWidgetFactory $factory)
Expand Down
1 change: 1 addition & 0 deletions plugins/Actions/Reports/GetEntryPageUrls.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ protected function init()
$this->actionToLoadSubTables = $this->action;
$this->subcategoryId = 'Actions_SubmenuPagesEntry';
$this->hasGoalMetrics = true;
$this->hasGoalSumMetrics = false;
}

public function getProcessedMetrics()
Expand Down
1 change: 1 addition & 0 deletions plugins/Actions/Reports/GetPageTitles.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ protected function init()
$this->actionToLoadSubTables = $this->action;
$this->subcategoryId = 'Actions_SubmenuPageTitles';
$this->hasGoalMetrics = true;
$this->hasGoalSumMetrics = false;
}

public function getMetrics()
Expand Down
1 change: 1 addition & 0 deletions plugins/Actions/Reports/GetPageUrls.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ protected function init()

$this->subcategoryId = 'General_Pages';
$this->hasGoalMetrics = true;
$this->hasGoalSumMetrics = false;
}

public function configureWidgets(WidgetsList $widgetsList, ReportWidgetFactory $factory)
Expand Down
3 changes: 2 additions & 1 deletion plugins/CustomDimensions/CustomDimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ public function getReportsWithGoalMetrics(&$reportsWithGoals)
'name' => $dimension['name'],
'module' => $this->pluginName,
'action' => 'getCustomDimension',
'parameters' => array('idDimension' => $dimension['idcustomdimension'])
'parameters' => array('idDimension' => $dimension['idcustomdimension']),
'hasGoalSumMetrics' => true,
);
}
}
Expand Down
19 changes: 12 additions & 7 deletions plugins/Goals/Goals.php
Original file line number Diff line number Diff line change
Expand Up @@ -387,14 +387,18 @@ public function getReportMetadataEnd(&$reports, $info)
&& empty($apiReportToUpdate['parameters'])
) {
// add overall Goal metrics computed during archiving by EnrichRecordWithGoalMetricSums
$apiReportToUpdate['metrics']['nb_conversions'] = $goalMetrics['nb_conversions'];
$apiReportToUpdate['metrics']['revenue'] = $goalMetrics['revenue'];
if (!isset($reportsWithGoals['hasGoalSumMetrics'])

Check failure on line 390 in plugins/Goals/Goals.php

View workflow job for this annotation

GitHub Actions / PHPCS

The first expression of a multi-line control structure must be on the line after the opening parenthesis
|| $reportWithGoals['hasGoalSumMetrics']
) {
$apiReportToUpdate['metrics']['nb_conversions'] = $goalMetrics['nb_conversions'];
$apiReportToUpdate['metrics']['revenue'] = $goalMetrics['revenue'];

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

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

$apiReportToUpdate['metricsGoal'] = $goalMetricsToUse;
$apiReportToUpdate['processedMetricsGoal'] = $goalProcessedMetricsToUse;
Expand All @@ -418,7 +422,8 @@ private static function getAllReportsWithGoalMetrics()
'name' => $report->getName(),
'module' => $report->getModule(),
'action' => $report->getAction(),
'parameters' => $report->getParameters()
'parameters' => $report->getParameters(),
'hasGoalSumMetrics' => $report->hasGoalSumMetrics(),
);
}
}
Expand Down

0 comments on commit b4d1125

Please sign in to comment.