Skip to content

Commit

Permalink
keep the gcd parameter on ecommerce events
Browse files Browse the repository at this point in the history
  • Loading branch information
bjesus committed Aug 13, 2024
1 parent 759d2e8 commit a37816a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@managed-components/google-analytics-4",
"version": "1.1.3",
"version": "1.1.4",
"description": "",
"main": "dist/index.js",
"scripts": {
Expand Down
1 change: 0 additions & 1 deletion src/ecommerce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const PRODUCT_DETAILS: string[] = [
'quantity',
'coupon',
'position',

'affiliation',
'discount',
'currency',
Expand Down
7 changes: 4 additions & 3 deletions src/requestBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ function getToolRequest(
// avoid sending ecommerce flattened products list to GA4
const { client, payload: fullPayload } = event
if (eventType === 'ecommerce') {
const restOfPayload: Record<string, unknown> = {}
const ecommercePayload: Record<string, unknown> = {}
for (const key of Object.keys(fullPayload.ecommerce)) {
if (
key !== 'products' &&
key !== 'currency' &&
!PREFIX_PARAMS_MAPPING[key]
) {
restOfPayload[key] = fullPayload.ecommerce[key]
ecommercePayload[key] = fullPayload.ecommerce[key]
}
}
payload = restOfPayload
if (fullPayload.gcd) ecommercePayload.gcd = fullPayload.gcd
payload = ecommercePayload
} else {
payload = fullPayload
}
Expand Down

0 comments on commit a37816a

Please sign in to comment.