Skip to content

Commit 308076c

Browse files
mmustafa-tsermi22186
authored andcommitted
feat: Map product position to GA4 item index (#62)
1 parent 126bcb3 commit 308076c

3 files changed

Lines changed: 21 additions & 18 deletions

File tree

packages/GA4Client/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/GA4Client/src/commerce-handler.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,9 @@ function parseProduct(product, affiliation) {
435435
case 'Variant':
436436
productWithAllAttributes.item_variant = product.Variant;
437437
break;
438+
case 'Position':
439+
productWithAllAttributes.index = product.Position;
440+
break;
438441
case 'Attributes':
439442
break;
440443
default:

packages/GA4Client/test/src/tests.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ describe('Google Analytics 4 Event', function () {
303303
item_id: 'iphoneSKU',
304304
item_name: 'iphone',
305305
item_variant: 'variant',
306-
position: 1,
306+
index: 1,
307307
price: 999,
308308
quantity: 1,
309309
total_amount: 999,
@@ -319,7 +319,7 @@ describe('Google Analytics 4 Event', function () {
319319
item_id: 'iphoneSKU',
320320
item_name: 'iphone',
321321
item_variant: 'variant',
322-
position: 1,
322+
index: 1,
323323
price: 999,
324324
quantity: 1,
325325
total_amount: 999,
@@ -806,7 +806,7 @@ describe('Google Analytics 4 Event', function () {
806806
item_id: 'iphoneSKU',
807807
item_name: 'iphone',
808808
item_variant: 'variant',
809-
position: 1,
809+
index: 1,
810810
price: 999,
811811
quantity: 1,
812812
total_amount: 999,
@@ -820,7 +820,7 @@ describe('Google Analytics 4 Event', function () {
820820
item_id: 'iphoneSKU',
821821
item_name: 'iphone',
822822
item_variant: 'variant',
823-
position: 1,
823+
index: 1,
824824
price: 999,
825825
quantity: 1,
826826
total_amount: 999,
@@ -1071,7 +1071,7 @@ describe('Google Analytics 4 Event', function () {
10711071
item_id: 'iphoneSKU',
10721072
item_name: 'iphone',
10731073
item_variant: 'variant',
1074-
position: 1,
1074+
index: 1,
10751075
price: 999,
10761076
quantity: 1,
10771077
total_amount: 999,
@@ -1085,7 +1085,7 @@ describe('Google Analytics 4 Event', function () {
10851085
item_id: 'iphoneSKU',
10861086
item_name: 'iphone',
10871087
item_variant: 'variant',
1088-
position: 1,
1088+
index: 1,
10891089
price: 999,
10901090
quantity: 1,
10911091
total_amount: 999,
@@ -1169,7 +1169,7 @@ describe('Google Analytics 4 Event', function () {
11691169
item_id: 'iphoneSKU',
11701170
item_name: 'iphone',
11711171
item_variant: 'variant',
1172-
position: 1,
1172+
index: 1,
11731173
price: 999,
11741174
quantity: 1,
11751175
total_amount: 999,
@@ -1183,7 +1183,7 @@ describe('Google Analytics 4 Event', function () {
11831183
item_id: 'iphoneSKU',
11841184
item_name: 'iphone',
11851185
item_variant: 'variant',
1186-
position: 1,
1186+
index: 1,
11871187
price: 999,
11881188
quantity: 1,
11891189
total_amount: 999,
@@ -1352,7 +1352,7 @@ describe('Google Analytics 4 Event', function () {
13521352
item_id: 'iphoneSKU',
13531353
item_name: 'iphone',
13541354
item_variant: 'variant',
1355-
position: 1,
1355+
index: 1,
13561356
price: 999,
13571357
quantity: 1,
13581358
total_amount: 999,
@@ -1366,7 +1366,7 @@ describe('Google Analytics 4 Event', function () {
13661366
item_id: 'iphoneSKU',
13671367
item_name: 'iphone',
13681368
item_variant: 'variant',
1369-
position: 1,
1369+
index: 1,
13701370
price: 999,
13711371
quantity: 1,
13721372
total_amount: 999,
@@ -1989,7 +1989,7 @@ describe('Google Analytics 4 Event', function () {
19891989
item_id: 'iphoneSKU',
19901990
item_name: 'iphone',
19911991
item_variant: 'variant',
1992-
position: 1,
1992+
index: 1,
19931993
price: 999,
19941994
quantity: 1,
19951995
total_amount: 999,
@@ -2252,7 +2252,7 @@ describe('Google Analytics 4 Event', function () {
22522252
item_id: 'iphoneSKU',
22532253
item_name: 'iphone',
22542254
item_variant: 'variant',
2255-
position: 1,
2255+
index: 1,
22562256
price: 999,
22572257
quantity: 1,
22582258
test4ever___: 'tester',
@@ -2268,7 +2268,7 @@ describe('Google Analytics 4 Event', function () {
22682268
item_id: 'iphoneSKU',
22692269
item_name: 'iphone',
22702270
item_variant: 'variant',
2271-
position: 1,
2271+
index: 1,
22722272
price: 999,
22732273
quantity: 1,
22742274
total_amount: 999,
@@ -2354,7 +2354,7 @@ describe('Google Analytics 4 Event', function () {
23542354
item_id: 'iphoneSKU',
23552355
item_name: 'iphone',
23562356
item_variant: 'variant',
2357-
position: 1,
2357+
index: 1,
23582358
price: 999,
23592359
quantity: 1,
23602360
total_amount: 999,
@@ -2371,7 +2371,7 @@ describe('Google Analytics 4 Event', function () {
23712371
item_id: 'iphoneSKU',
23722372
item_name: 'iphone',
23732373
item_variant: 'variant',
2374-
position: 1,
2374+
index: 1,
23752375
price: 999,
23762376
quantity: 1,
23772377
total_amount: 999,
@@ -2456,7 +2456,7 @@ describe('Google Analytics 4 Event', function () {
24562456
item_id: 'iphoneSKU',
24572457
item_name: 'iphone',
24582458
item_variant: 'variant',
2459-
position: 1,
2459+
index: 1,
24602460
price: 999,
24612461
quantity: 1,
24622462
total_amount: 999,
@@ -2473,7 +2473,7 @@ describe('Google Analytics 4 Event', function () {
24732473
item_id: 'iphoneSKU',
24742474
item_name: 'iphone',
24752475
item_variant: 'variant',
2476-
position: 1,
2476+
index: 1,
24772477
price: 999,
24782478
quantity: 1,
24792479
total_amount: 999,

0 commit comments

Comments
 (0)