From d758505dffbbadeab86758ad522e4fc7af4abf17 Mon Sep 17 00:00:00 2001 From: Yair Dovrat Date: Wed, 5 Jun 2024 13:35:14 +0200 Subject: [PATCH] ZRZ-1327 make sure products is an array before running map() --- src/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index aa7f3df..0d31491 100644 --- a/src/index.ts +++ b/src/index.ts @@ -27,7 +27,9 @@ const getECParams = (event: MCEvent) => { payload.name || payload.product_id || payload.sku || - payload.products?.map((p: any) => p.name).join() + Array.isArray(payload.products) + ? payload.products.map((p: any) => p.name).join() + : '' data.ev = payload.price || payload.total || payload.value data.gv = payload.price || data.gv break @@ -48,7 +50,9 @@ const getECParams = (event: MCEvent) => { payload.checkout_id || payload.product_id || payload.name || - payload.products?.map((p: any) => p.name).join() + Array.isArray(payload.products) + ? payload.products.map((p: any) => p.name).join() + : '' data.ev = payload.revenue || payload.total || payload.value || payload.price }