Skip to content

Commit 50e81af

Browse files
jborlase-snowplowgreg-el
authored andcommitted
Fixing GA4 Add To Cart for GTM Ecommerce Template (snowplow#1435)
Fixing GA4 Add To Cart for GTM Ecommerce Template
1 parent 25ac7f9 commit 50e81af

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@snowplow/browser-plugin-snowplow-ecommerce",
5+
"comment": "Fixing GA4 Ecommerce functions to use finalCartValue within ecommerce object",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@snowplow/browser-plugin-snowplow-ecommerce"
10+
}

plugins/browser-plugin-snowplow-ecommerce/src/ga4/api.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,23 @@ export function trackGA4SelectPromotion(ecommerce: GA4EcommerceObject & Promotio
3333
}
3434

3535
export function trackGA4AddToCart(
36-
ecommerce: GA4EcommerceObject & Currency,
36+
ecommerce: GA4EcommerceObject & Currency & { finalCartValue?: number },
3737
opts: Options & { finalCartValue: number }
3838
) {
3939
const currency = (ecommerce.currency || opts.currency)!;
40+
const finalCartValue = ecommerce.finalCartValue ?? opts.finalCartValue;
4041
const products = transformG4ItemsToSPProducts(ecommerce, currency);
41-
trackAddToCart({ products, total_value: opts.finalCartValue, currency });
42+
trackAddToCart({ products, total_value: finalCartValue, currency });
4243
}
4344

4445
export function trackGA4RemoveFromCart(
45-
ecommerce: GA4EcommerceObject & Currency,
46+
ecommerce: GA4EcommerceObject & Currency & { finalCartValue?: number },
4647
opts: Options & { finalCartValue: number }
4748
) {
4849
const currency = (ecommerce.currency || opts.currency)!;
50+
const finalCartValue = ecommerce.finalCartValue ?? opts.finalCartValue;
4951
const products = transformG4ItemsToSPProducts(ecommerce, currency);
50-
trackRemoveFromCart({ products, total_value: opts.finalCartValue, currency });
52+
trackRemoveFromCart({ products, total_value: finalCartValue, currency });
5153
}
5254

5355
export function trackGA4ViewItem(ecommerce: GA4EcommerceObject, opts: Options = {}) {

0 commit comments

Comments
 (0)