Skip to content

Commit

Permalink
For pre-5.1 Matomo versions, manually make overall Conversions and Re…
Browse files Browse the repository at this point in the history
…venue metrics available (will not be translated).
  • Loading branch information
diosmosis committed Jun 3, 2024
1 parent 5513485 commit 5f7fa04
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,21 @@ function getFieldsFromReportMetadata(reportMetadata: Api.ReportMetadata, goals:
allMetrics = { ...allMetrics, ...metricsForEachGoal(reportMetadata.processedMetricsGoal, goals) };
}

// add goal specific conversion_rate if not present in metadata, but other goal metrics are
// (in 4.x-dev, this is removed in the API despite the data being available)
if (
(reportMetadata.metricsGoal || reportMetadata.processedMetricsGoal)
&& (!reportMetadata.metricsGoal?.conversion_rate && !reportMetadata.processedMetricsGoal?.conversion_rate)
) {
allMetrics = { ...allMetrics, ...metricsForEachGoal({ 'conversion_rate': 'Conversion Rate' }, goals) };
if (reportMetadata.metricsGoal || reportMetadata.processedMetricsGoal) {
// add goal specific conversion_rate if not present in metadata, but other goal metrics are
// (in 4.x-dev, this is removed in the API despite the data being available)
if (!reportMetadata.metricsGoal?.conversion_rate && !reportMetadata.processedMetricsGoal?.conversion_rate) {
allMetrics = { ...allMetrics, ...metricsForEachGoal({ 'conversion_rate': 'Conversion Rate' }, goals) };
}

// pre 5.1.0, the overall conversions and revenue sum metrics were not present in metadata output,
// but the data exists in the actual API output
if (!reportMetadata.metrics?.conversion) {
allMetrics['nb_conversions'] = 'Conversions';
}
if (!reportMetadata.metrics?.revenue) {
allMetrics['revenue'] = 'Revenue';
}
}

if (!requestedFields?.length) {
Expand Down

0 comments on commit 5f7fa04

Please sign in to comment.