Skip to content

Commit acf87f2

Browse files
committed
Keep all keys when building ecommerce product
Removes product details mapping, which is unnecessary now that unknown keys are accepted.
1 parent 0207c2a commit acf87f2

File tree

2 files changed

+3
-35
lines changed

2 files changed

+3
-35
lines changed

src/ecommerce.ts

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,6 @@ const EVENTS: { [k: string]: string } = {
1616
'Order Refunded': 'refund',
1717
}
1818

19-
const PRODUCT_DETAILS: string[] = [
20-
'cart_id',
21-
'product_id',
22-
'sku',
23-
'category',
24-
'name',
25-
'brand',
26-
'variant',
27-
'price',
28-
'quantity',
29-
'coupon',
30-
'position',
31-
32-
'affiliation',
33-
'discount',
34-
'currency',
35-
]
36-
3719
// list of params that will be prefixed in the request with
3820
// ep for string values
3921
// epn for numbers
@@ -117,15 +99,4 @@ const buildProductRequest = (item: { [k: string]: any }) => {
11799
return resultList.join('~')
118100
}
119101

120-
// product comes in standard format
121-
// returns GA4's standard item
122-
const mapProductToItem = (product: any) => {
123-
const eventProductDescription = PRODUCT_DETAILS
124-
const item: any = {}
125-
for (const prop of eventProductDescription) {
126-
product[prop] && (item[prop] = product[prop])
127-
}
128-
return item
129-
}
130-
131-
export { EVENTS, mapProductToItem, PREFIX_PARAMS_MAPPING, buildProductRequest }
102+
export { EVENTS, PREFIX_PARAMS_MAPPING, buildProductRequest }

src/requestBuilder.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { ComponentSettings, MCEvent } from '@managed-components/types'
22
import {
33
buildProductRequest,
44
EVENTS,
5-
mapProductToItem,
65
PREFIX_PARAMS_MAPPING,
76
} from './ecommerce'
87
import { flattenKeys, isNumber } from './utils'
@@ -169,14 +168,12 @@ const getFinalURL = (
169168
if (ecommerceData.products) {
170169
// handle products list
171170
for (const [index, product] of (ecommerceData.products || []).entries()) {
172-
const item = mapProductToItem(product)
173-
prQueryParams = buildProductRequest(item)
171+
prQueryParams = buildProductRequest(product)
174172
toolRequest[`pr${index + 1}`] = prQueryParams
175173
}
176174
} else {
177175
// handle single product data
178-
const item = mapProductToItem(ecommerceData)
179-
prQueryParams = buildProductRequest(item)
176+
prQueryParams = buildProductRequest(ecommerceData)
180177
if (prQueryParams) toolRequest['pr1'] = prQueryParams
181178
}
182179
}

0 commit comments

Comments
 (0)