Skip to content

Fixing GA4 Add To Cart for GTM Ecommerce Template#1435

Merged
Greg Leonard (greg-el) merged 4 commits intosnowplow:release/4.6.4from
jborlase-snowplow:ga4-ecommerce-fix
Jun 23, 2025
Merged

Fixing GA4 Add To Cart for GTM Ecommerce Template#1435
Greg Leonard (greg-el) merged 4 commits intosnowplow:release/4.6.4from
jborlase-snowplow:ga4-ecommerce-fix

Conversation

@jborlase-snowplow
Copy link
Copy Markdown
Contributor

The current implementation of the trackGA4AddToCart is incompatible with the Snowplow Ecommerce tag template. The tag template combines the opts and ecommerce objects. There is no method to pass multiple parameters through the GTM template. The result is that the add to cart and remove to cart events are always invalid since they require a total_value property that comes from the finalCartValue.

This fix allows the JavaScript tracker to check the ecommerce object for the finalCartValue.

Jethro Nederhof (jethron) added a commit to snowplow/snowplow-gtm-tag-template-ecommerce-v3 that referenced this pull request May 29, 2025
Per snowplow/snowplow-javascript-tracker#1435 the handling of `opts` parameter assumes both it and the `ecommerce` object will be checked for each option, but this is not the case in some cases (e.g. `finalCartValue`, `step`, `paymentMethod`). This corrects the interface selection so the parameters are passed correctly.
Jethro Nederhof (jethron) added a commit to snowplow/snowplow-gtm-tag-template-ecommerce-v3 that referenced this pull request May 29, 2025
Per snowplow/snowplow-javascript-tracker#1435 the handling of `opts` parameter assumes both it and the `ecommerce` object will be checked for each option, but this is not the case in some cases (e.g. `finalCartValue`, `step`, `paymentMethod`). This corrects the interface selection so the parameters are passed correctly.
@matus-tomlein Matus Tomlein (matus-tomlein) changed the base branch from master to release/4.6.4 May 29, 2025 19:53
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution, jborlase-snowplow! LGTM, but adding Peter Perlepes (@igneel64) for a second pair of eyes as I don't have much experience with this use case.

Comment thread plugins/browser-plugin-snowplow-ecommerce/src/ga4/api.ts Outdated
Comment thread plugins/browser-plugin-snowplow-ecommerce/src/ga4/api.ts Outdated
jborlase-snowplow and others added 2 commits May 30, 2025 12:27
Nice! I should really spend some time learning TypeScript.

Co-authored-by: Matus Tomlein <matus.tomlein@gmail.com>
Including Matus' feedback

Co-authored-by: Matus Tomlein <matus.tomlein@gmail.com>
Copy link
Copy Markdown
Contributor

@greg-el Greg Leonard (greg-el) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one! LGTM!

@greg-el Greg Leonard (greg-el) merged commit 90c9639 into snowplow:release/4.6.4 Jun 23, 2025
1 check failed
Greg Leonard (greg-el) pushed a commit that referenced this pull request Jun 23, 2025
Fixing GA4 Add To Cart for GTM Ecommerce Template
Jethro Nederhof (jethron) added a commit to snowplow/snowplow-gtm-tag-template-ecommerce-v3 that referenced this pull request Jun 23, 2025
Per snowplow/snowplow-javascript-tracker#1435 the handling of `opts` parameter assumes both it and the `ecommerce` object will be checked for each option, but this is not the case in some cases (e.g. `finalCartValue`, `step`, `paymentMethod`). This corrects the interface selection so the parameters are passed correctly.
Greg Leonard (greg-el) pushed a commit that referenced this pull request Jun 25, 2025
Fixing GA4 Add To Cart for GTM Ecommerce Template
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants