From f7380d423df6c8663655dc7c15b28291b92964da Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Wed, 6 Sep 2023 16:02:54 -0400 Subject: [PATCH] fix: Map CouponCode to reserved attributes `coupon` (#50) --- packages/GA4Client/src/commerce-handler.js | 3 +++ packages/GA4Client/test/src/tests.js | 27 +++++++++++----------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/GA4Client/src/commerce-handler.js b/packages/GA4Client/src/commerce-handler.js index ba6a4fa..2a154da 100644 --- a/packages/GA4Client/src/commerce-handler.js +++ b/packages/GA4Client/src/commerce-handler.js @@ -282,6 +282,9 @@ function parseProduct(product) { case 'Category': productWithAllAttributes.item_category = product.Category; break; + case 'CouponCode': + productWithAllAttributes.coupon = product.CouponCode; + break; case 'Variant': productWithAllAttributes.item_variant = product.Variant; break; diff --git a/packages/GA4Client/test/src/tests.js b/packages/GA4Client/test/src/tests.js index 08f337d..0641321 100644 --- a/packages/GA4Client/test/src/tests.js +++ b/packages/GA4Client/test/src/tests.js @@ -279,7 +279,7 @@ describe('Google Analytics 4 Event', function () { value: 100, items: [ { - coupon_code: 'coupon', + coupon: 'coupon', item_brand: 'brand', item_category: 'category', item_id: 'iphoneSKU', @@ -295,7 +295,7 @@ describe('Google Analytics 4 Event', function () { { eventMetric1: 'metric1', journeyType: 'testjourneytype2', - coupon_code: 'coupon', + coupon: 'coupon', item_brand: 'brand', item_category: 'category', item_id: 'iphoneSKU', @@ -779,7 +779,7 @@ describe('Google Analytics 4 Event', function () { { eventMetric1: 'metric2', journeyType: 'testjourneytype1', - coupon_code: 'coupon', + coupon: 'coupon', item_brand: 'brand', item_category: 'category', item_id: 'iphoneSKU', @@ -793,7 +793,7 @@ describe('Google Analytics 4 Event', function () { { eventMetric1: 'metric1', journeyType: 'testjourneytype2', - coupon_code: 'coupon', + coupon: 'coupon', item_brand: 'brand', item_category: 'category', item_id: 'iphoneSKU', @@ -1040,7 +1040,7 @@ describe('Google Analytics 4 Event', function () { { eventMetric1: 'metric2', journeyType: 'testjourneytype1', - coupon_code: 'coupon', + coupon: 'coupon', item_brand: 'brand', item_category: 'category', item_id: 'iphoneSKU', @@ -1054,7 +1054,7 @@ describe('Google Analytics 4 Event', function () { { eventMetric1: 'metric1', journeyType: 'testjourneytype2', - coupon_code: 'coupon', + coupon: 'coupon', item_brand: 'brand', item_category: 'category', item_id: 'iphoneSKU', @@ -1137,7 +1137,7 @@ describe('Google Analytics 4 Event', function () { { eventMetric1: 'metric2', journeyType: 'testjourneytype1', - coupon_code: 'coupon', + coupon: 'coupon', item_brand: 'brand', item_category: 'category', item_id: 'iphoneSKU', @@ -1151,7 +1151,7 @@ describe('Google Analytics 4 Event', function () { { eventMetric1: 'metric1', journeyType: 'testjourneytype2', - coupon_code: 'coupon', + coupon: 'coupon', item_brand: 'brand', item_category: 'category', item_id: 'iphoneSKU', @@ -1317,7 +1317,7 @@ describe('Google Analytics 4 Event', function () { { eventMetric1: 'metric2', journeyType: 'testjourneytype1', - coupon_code: 'coupon', + coupon: 'coupon', item_brand: 'brand', item_category: 'category', item_id: 'iphoneSKU', @@ -1331,7 +1331,7 @@ describe('Google Analytics 4 Event', function () { { eventMetric1: 'metric1', journeyType: 'testjourneytype2', - coupon_code: 'coupon', + coupon: 'coupon', item_brand: 'brand', item_category: 'category', item_id: 'iphoneSKU', @@ -1820,7 +1820,6 @@ describe('Google Analytics 4 Event', function () { }); }); }); - }); describe('identity', function () { @@ -2047,7 +2046,7 @@ describe('Google Analytics 4 Event', function () { eventMetric1: 'metric1', journeyType: 'testjourneytype2', test4ever___: 'tester', - coupon_code: 'coupon', + coupon: 'coupon', item_brand: 'brand', item_category: 'category', item_id: 'iphoneSKU', @@ -2132,7 +2131,7 @@ describe('Google Analytics 4 Event', function () { { eventMetric1: 'metric2', journeyType: 'testjourneytype1', - coupon_code: 'coupon', + coupon: 'coupon', item_brand: 'brand', item_category: 'category', item_id: 'iphoneSKU', @@ -2149,7 +2148,7 @@ describe('Google Analytics 4 Event', function () { { eventMetric1: 'metric1', journeyType: 'testjourneytype2', - coupon_code: 'coupon', + coupon: 'coupon', item_brand: 'brand', item_category: 'category', item_id: 'iphoneSKU',