From 924ae9465f227e9c2309459555422dc079eae656 Mon Sep 17 00:00:00 2001 From: Ivan Kalachikov Date: Thu, 12 Dec 2024 17:34:58 +0100 Subject: [PATCH] fix: sonar issues --- client-app/modules/google-analytics/events.ts | 10 +++++----- client-app/modules/google-analytics/utils.ts | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/client-app/modules/google-analytics/events.ts b/client-app/modules/google-analytics/events.ts index 744a3af0b..d941beb70 100644 --- a/client-app/modules/google-analytics/events.ts +++ b/client-app/modules/google-analytics/events.ts @@ -8,14 +8,14 @@ import type { TackerType } from "@/core/types/analytics"; const { currencyCode } = globals; export const analytics: TackerType = { - viewItemList(items = [], params) { + viewItemList(items, params) { sendEvent("view_item_list", { ...params, - items_skus: items + items_skus: (items ?? []) .map((el) => el.code) .join(", ") .trim(), - items_count: items.length, + items_count: items?.length ?? 0, }); }, @@ -45,13 +45,13 @@ export const analytics: TackerType = { }); }, - addItemToCart(item, quantity = 1, params) { + addItemToCart(item, quantity, params) { const inputItem = productToGtagItem(item); inputItem.quantity = quantity; sendEvent("add_to_cart", { ...params, currency: currencyCode, - value: (item.price?.actual?.amount || 0) * quantity, + value: (item.price?.actual?.amount || 0) * (quantity ?? 1), items: [inputItem], }); }, diff --git a/client-app/modules/google-analytics/utils.ts b/client-app/modules/google-analytics/utils.ts index 65c8230f7..bc80d45e4 100644 --- a/client-app/modules/google-analytics/utils.ts +++ b/client-app/modules/google-analytics/utils.ts @@ -44,7 +44,7 @@ export function lineItemToGtagItem( index, item_id: item.sku, item_name: item.name, - affiliation: item.vendor?.name || "?", + affiliation: item.vendor?.name ?? "?", currency: item.placedPrice.currency.code, discount: item.discountAmount?.amount || item.discountTotal?.amount, price: "price" in item ? item.price.amount : item.listPrice.amount,