matomo-org / plugin-GoogleAnalyticsImporter

Google Analytics to Matomo importer
24 stars 14 forks source link

GA4 Importer doesn't import E-Commerce data - in contrast to UA #516

Open obottek opened 5 months ago

obottek commented 5 months ago

Hi,

I'm just loading data of some Universal Analytics properties, including e-commerce details. Now I'm on my way to do the same with the GA4 properties. However in contract to the UA importer, the GA4 importer doesn't import so important information as e-commerce revenue, conversion rate and no products details at all. Also goal values look wrong. Except for the conversion rate, everything else was fine with the UA importer.

I also checked the GA4 Query Explorer and it looks all values are possible to fetch there.

Here is a query for product details: {"dimensions":[{"name":"itemId"},{"name":"itemName"}],"metrics":[{"name":"itemRevenue"},{"name":"itemsPurchased"}],"dateRanges":[{"startDate":"2023-06-01","endDate":"2023-06-30"}]}

And the result: {"dimensionHeaders":[{"name":"itemId"},{"name":"itemName"}],"metricHeaders":[{"name":"itemRevenue","type":"TYPE_CURRENCY"},{"name":"itemsPurchased","type":"TYPE_INTEGER"}],"rows":[{"dimensionValues":[{"value":"561020"},{"value":"NERF - Super Soaker XP100"}],"metricValues":[{"value":"499.782208"},{"value":"20"}]}],"rowCount":243,"metadata":{"schemaRestrictionResponse":{},"currencyCode":"EUR","timeZone":"Europe/Berlin"},"kind":"analyticsData#runReport"}

Query for E-Commerce Purchases, Revenue and Session Conversion Rate: {"metrics":[{"name":"ecommercePurchases"},{"name":"purchaseRevenue"},{"name":"sessionConversionRate"}],"dateRanges":[{"startDate":"2023-06-01","endDate":"2023-06-30"}],"limit":"1"}

Result: {"metricHeaders":[{"name":"sessionConversionRate","type":"TYPE_FLOAT"}],"rows":[{"metricValues":{"metricHeaders":[{"name":"ecommercePurchases","type":"TYPE_INTEGER"},{"name":"purchaseRevenue","type":"TYPE_CURRENCY"},{"name":"sessionConversionRate","type":"TYPE_FLOAT"}],"rows":[{"metricValues":[{"value":"259"},{"value":"13669.916495000001"},{"value":"0.014340291235258292"}]}],"rowCount":1,"metadata":{"schemaRestrictionResponse":{},"currencyCode":"EUR","timeZone":"Europe/Berlin"},"kind":"analyticsData#runReport"}

That should be possible to request and process, right?

It would be great to have this build into the importer soon, because as of 1st July 2024, only GA4 properties hold data and also they only keep 14 month. So time to transfer runs out.

I'm on Matomo 5.0.3 and GoogleAnalyticsImporter plugin 5.0.12.

Greetings, Olaf

obottek commented 5 months ago

I just see that the E-Commerce part is outcommented in the GA4 importer and that the code still has the ua attribute names. Maybe this could be updated to the ones I have given above?

Greetings, Olaf

snake14 commented 5 months ago

Hi @obottek . Thank you for taking the time to create this issue. It does indeed look like version 4.4.8 of the plugin removed the itemRevenue and itemsPurchased metrics due to incompatibility. I'll mark this issue to be reviewed and prioritised by our Product team.

AltamashShaikh commented 5 months ago

@obottek If you replace the code in plugins/GoogleAnalyticsImporter/Google/GoogleGA4MetricMapper.php with the content from this URL and start a new import, does that work for you ?

AltamashShaikh commented 1 month ago

I just tried it and this still doesn't work.

Google Analytics returned an error: {
    "message": "Please remove itemRevenue and itemPurchaseQuantity to make the request compatible for example. The request's dimensions & metrics are incompatible. To learn more, see https:\/\/ga-dev-tools.web.app\/ga4\/dimensions-metrics-explorer\/",
    "code": 3,
    "status": "INVALID_ARGUMENT",
    "details": []
}
INFO      [2024-07-30 06:31:21] 1415150  Unexpected Error: Matomo\Dependencies\GoogleAnalyticsImporter\Google\ApiCore\ApiException: {
    "message": "Please remove itemRevenue and itemPurchaseQuantity to make the request compatible for example. The request's dimensions & metrics are incompatible. To learn more, see https:\/\/ga-dev-tools.web.app\/ga4\/dimensions-metrics-explorer\/",
    "code": 3,
    "status": "INVALID_ARGUMENT",
    "details": []
}