rudderlabs / rudder-sdk-js

JavaScript SDK for RudderStack - the Customer Data Platform for Developers.
https://www.rudderstack.com
Other
143 stars 82 forks source link

BUG : GA4 Ecommerce (view_item, add_to_cart, add_to_wishlist, checkout_started) are missing critical fields #809

Closed balawa closed 1 year ago

balawa commented 1 year ago

Describe the bug The GA4 integration is not sending the required field according to the GA4 documentation. The field "value" is missing.

https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtag#add_to_cart https://developers.google.com/analytics/devguides/collection/ga4/reference/events?client_type=gtag#view_item

To Reproduce When you execute the following code: rudderanalytics.track("Product Added", { "category": "modern-style", "currency": "EUR", "name": "blue-sliding-door-modern-style", "price": 955, "product_id": "blue-sliding-door-modern-style" })

The SDK generate the correct API call to the data layer. { "channel": "web", "context": ...., "type": "track", "messageId": "1671795928209000-0ed86a9e-69f5-4f53-ae2e-30575ad8159e", "originalTimestamp": "2022-12-23T11:45:28.209Z", "anonymousId": "e2715f27-3c6d-4d73-9e7b-cb54b4aabbe8", "userId": "", "event": "Product Viewed", "properties": { "category": "modern-style", "currency": "EUR", "name": "blue-sliding-door-modern-style", "price": 955, "product_id": "blue-sliding-door-modern-style" }, "integrations": { "All": true }, "sentAt": "2022-12-23T11:45:28.218Z" }

however the integration is missing the value field and generate the following code: dataLayer.push({ event: "add_to_cart", eventModel: { items: [ { item_name: "blue-sliding-door-modern-style", price: 1040, item_id: "modern-style", quantity: 1, item_variant: "UHJvZHVjdFZhcmlhbnQ6MTQyMzc=", currency: "EUR" } ], currency: "EUR" }, gtm.uniqueEventId: 248 })

Expected behavior The expected behaviour is to generate the following call: dataLayer.push({ event: "add_to_cart", eventModel: { items: [ { item_name: "blue-sliding-door-modern-style", price: 1040, item_id: "modern-style", quantity: 1, item_variant: "UHJvZHVjdFZhcmlhbnQ6MTQyMzc=", currency: "EUR" } ], currency: "EUR", value: 1040 }, gtm.uniqueEventId: 248 })

Source of the Error The source of error could be traced back here: { src: ['product added'], dest: 'add_to_cart', requiredParams: [requiredEventParameters.ProductId, requiredEventParameters.ProductName], hasItem: true, includeList: [eventParametersConfigArray.Currency, eventParametersConfigArray.Total], }, ^^^^

where the code should be: { src: ['product added'], dest: 'add_to_cart', requiredParams: [requiredEventParameters.ProductId, requiredEventParameters.ProductName], hasItem: true, includeList: [eventParametersConfigArray.Currency, eventParametersConfigArray. Price], }, ^^^^

As the Rudderstack documentation does not accept the field total for

The issue also exist for

balawa commented 1 year ago

@yashasvibajpai it is great you have push a Fix in the main branch and it will be ship in the next release.

It would be great to reference the issue number in the push and reply to this thread so we could see if we should close the issue.

I have notice add_to_wishlist was not patched. What is therefore the expected behaviour when calling the sdk to capture the price info correctly.

yashasvibajpai commented 1 year ago

@balawa Thank you. I have referenced the related fixes in the PR descriptions. Also, can you please recheck for add_to_wishlist, a similar fix is done in the same PR and ready to ship with next release.

balawa commented 1 year ago

@yashasvibajpai Thank you for the fix. This is perfect. Would your mark the issue as closed ?