OpenMage / magento-lts

Official OpenMage LTS codebase | Migrate easily from Magento Community Edition in minutes! Download the source code for free or contribute to OpenMage LTS | Security vulnerability patches, bug fixes, performance improvements and more.
https://www.openmage.org
Open Software License 3.0
869 stars 436 forks source link

Google Analytics 4 / GA4 does not track conversions (orders) #3090

Closed loekvangool closed 1 year ago

loekvangool commented 1 year ago

https://github.com/OpenMage/magento-lts/pull/3023 implements the basic GA4 snippet from Google, but it's probably not ready for production.

I haven't run it, but by looking at the code, this PR does not implement order (conversion) tracking (_getOrdersTrackingCode()). Without conversion tracking, I would say that GA4 is not "ready". I think this is the right event to track: https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtag#purchase

Also, I cannot help notice that this PR was approved without proper testing, or at least if there was testing, it was not documented in the Issue (see discussion in https://github.com/OpenMage/magento-lts/pull/3023).

In order to implement conversion tracking, something like this is needed: https://github.com/OpenMage/magento-lts/blob/1.9.4.x/app/code/core/Mage/GoogleAnalytics/Block/Ga.php#L206

Note: It seems from GA4 docs that tracking pageviews is not necessary, hence in theory _getPageTrackingCode() does not need to be implemented for GA4.

fballiano commented 1 year ago

it never tracked conversions if I remember correctly, that's something for modules like Enhanced Commerce etc.

The PR tracks page visits, convertions and events depends too much on the business logic of the website and anyway it's not to be considered a "bug" of the current implementation.

loekvangool commented 1 year ago

It's a serious degradation of functionality. Without conversions, Google smart campaigns fail. At the very least it should be documented.

fballiano commented 1 year ago

the previous implementation (which is anyway still there) didn't track conversions either AFAIK so I don't understand the degradation...

loekvangool commented 1 year ago

the previous implementation (which is anyway still there) didn't track conversions either AFAIK so I don't understand the degradation...

I don't think so. I can confirm that orders are tracked with the pre-GA4 implementation. The code was already mentioned in my original post but it's here: https://github.com/OpenMage/magento-lts/blob/1.9.4.x/app/code/core/Mage/GoogleAnalytics/Block/Ga.php#L206

fballiano commented 1 year ago

ok, it should be quite easy to add

fballiano commented 1 year ago

I've created https://github.com/OpenMage/magento-lts/pull/3092 if you want to give it a try

loekvangool commented 1 year ago

Aprreciate it, I will find time for testing