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 (#64)

* For pre-5.1 Matomo versions, manually make overall Conversions and Revenue metrics available (will not be translated).

* Actions reports do not have goal sum metrics

* add metric types as well as the metrics themselves

* update expected test files
  • Loading branch information
diosmosis authored Jun 4, 2024
1 parent 5513485 commit ba0302e
Show file tree
Hide file tree
Showing 51 changed files with 1,178 additions and 58 deletions.
26 changes: 19 additions & 7 deletions src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,25 @@ 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.module !== 'Actions') {
if (!reportMetadata.metrics?.conversion) {
allMetrics['nb_conversions'] = 'Conversions';
reportMetadata.metricTypes['nb_conversions'] = 'number';
}
if (!reportMetadata.metrics?.revenue) {
allMetrics['revenue'] = 'Revenue';
reportMetadata.metricTypes['revenue'] = 'money';
}
}
}

if (!requestedFields?.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
"0.0335",
"0.0182",
"0.0014",
"0"
"0",
"38",
"24"
]
},
{
Expand Down Expand Up @@ -80,6 +82,8 @@
"0",
"0",
"0",
"0",
"0",
"0"
]
},
Expand Down Expand Up @@ -121,7 +125,9 @@
"0.0276",
"0",
"0",
"0"
"0",
"20",
"26"
]
},
{
Expand Down Expand Up @@ -162,6 +168,8 @@
"0",
"0",
"0",
"0",
"0",
"0"
]
},
Expand Down Expand Up @@ -203,7 +211,9 @@
"0.0265",
"0.01",
"0.0013",
"0"
"0",
"144",
"101"
]
}
],
Expand Down Expand Up @@ -575,6 +585,26 @@
"isReaggregatable": false,
"semanticType": "PERCENT"
}
},
{
"dataType": "NUMBER",
"label": "Conversions",
"name": "nb_conversions",
"semantics": {
"conceptType": "METRIC",
"isReaggregatable": false,
"semanticType": "NUMBER"
}
},
{
"dataType": "NUMBER",
"label": "Revenue",
"name": "revenue",
"semantics": {
"conceptType": "METRIC",
"isReaggregatable": false,
"semanticType": "CURRENCY_USD"
}
}
]
}
40 changes: 35 additions & 5 deletions tests/appscript/expected/data_DevicesDetection.getBrand.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"0.0222",
"0.0077",
"0.0039",
"0"
"0",
"65",
"6019.45"
]
},
{
Expand Down Expand Up @@ -78,7 +80,9 @@
"0.0251",
"0.0084",
"0",
"0"
"0",
"42",
"1437.6"
]
},
{
Expand Down Expand Up @@ -118,7 +122,9 @@
"0.0124",
"0.0248",
"0",
"0"
"0",
"8",
"180"
]
},
{
Expand Down Expand Up @@ -158,7 +164,9 @@
"0",
"0",
"0",
"0"
"0",
"1",
"2"
]
},
{
Expand Down Expand Up @@ -198,7 +206,9 @@
"0.0455",
"0",
"0",
"0"
"0",
"7",
"9"
]
}
],
Expand Down Expand Up @@ -561,6 +571,26 @@
"isReaggregatable": false,
"semanticType": "PERCENT"
}
},
{
"dataType": "NUMBER",
"label": "Conversions",
"name": "nb_conversions",
"semantics": {
"conceptType": "METRIC",
"isReaggregatable": false,
"semanticType": "NUMBER"
}
},
{
"dataType": "NUMBER",
"label": "Revenue",
"name": "revenue",
"semantics": {
"conceptType": "METRIC",
"isReaggregatable": false,
"semanticType": "CURRENCY_USD"
}
}
]
}
40 changes: 35 additions & 5 deletions tests/appscript/expected/data_DevicesDetection.getBrowsers.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"0.0204",
"0.0079",
"0.0045",
"0"
"0",
"55",
"4947.4"
]
},
{
Expand Down Expand Up @@ -78,7 +80,9 @@
"0.032",
"0.0145",
"0",
"0"
"0",
"16",
"11"
]
},
{
Expand Down Expand Up @@ -118,7 +122,9 @@
"0.021",
"0.0168",
"0",
"0"
"0",
"11",
"9"
]
},
{
Expand Down Expand Up @@ -158,7 +164,9 @@
"0.021",
"0.0042",
"0",
"0"
"0",
"17",
"1208.8"
]
},
{
Expand Down Expand Up @@ -198,7 +206,9 @@
"0.0252",
"0.0042",
"0",
"0"
"0",
"24",
"1471.85"
]
}
],
Expand Down Expand Up @@ -561,6 +571,26 @@
"isReaggregatable": false,
"semanticType": "PERCENT"
}
},
{
"dataType": "NUMBER",
"label": "Conversions",
"name": "nb_conversions",
"semantics": {
"conceptType": "METRIC",
"isReaggregatable": false,
"semanticType": "NUMBER"
}
},
{
"dataType": "NUMBER",
"label": "Revenue",
"name": "revenue",
"semantics": {
"conceptType": "METRIC",
"isReaggregatable": false,
"semanticType": "CURRENCY_USD"
}
}
]
}
40 changes: 35 additions & 5 deletions tests/appscript/expected/data_DevicesDetection.getModel.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
"0.0221",
"0.008",
"0.004",
"0"
"0",
"64",
"6018.45"
]
},
{
Expand Down Expand Up @@ -78,7 +80,9 @@
"0.0186",
"0.0047",
"0",
"0"
"0",
"24",
"1424.6"
]
},
{
Expand Down Expand Up @@ -118,7 +122,9 @@
"0.0256",
"0.0128",
"0",
"0"
"0",
"12",
"8"
]
},
{
Expand Down Expand Up @@ -158,7 +164,9 @@
"0.0532",
"0.0106",
"0",
"0"
"0",
"6",
"5"
]
},
{
Expand Down Expand Up @@ -198,7 +206,9 @@
"0.023",
"0.0115",
"0",
"0"
"0",
"17",
"192"
]
}
],
Expand Down Expand Up @@ -561,6 +571,26 @@
"isReaggregatable": false,
"semanticType": "PERCENT"
}
},
{
"dataType": "NUMBER",
"label": "Conversions",
"name": "nb_conversions",
"semantics": {
"conceptType": "METRIC",
"isReaggregatable": false,
"semanticType": "NUMBER"
}
},
{
"dataType": "NUMBER",
"label": "Revenue",
"name": "revenue",
"semantics": {
"conceptType": "METRIC",
"isReaggregatable": false,
"semanticType": "CURRENCY_USD"
}
}
]
}
Loading

0 comments on commit ba0302e

Please sign in to comment.