From e09e1c731dac21553a7658a5fc9c4c06661542e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Grz=C4=85ba?= Date: Wed, 24 Jan 2024 14:04:18 +0100 Subject: [PATCH] adds support for deprecated addEcommerceItem method --- example/src/pages/ECommercePage.tsx | 2 +- src/constants/track-event.constant.ts | 5 ++-- src/services/e-commerce/e-commerce.service.ts | 23 +++++++++++++++++-- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/example/src/pages/ECommercePage.tsx b/example/src/pages/ECommercePage.tsx index 7dc57b2..355abc6 100644 --- a/example/src/pages/ECommercePage.tsx +++ b/example/src/pages/ECommercePage.tsx @@ -105,7 +105,7 @@ const ECommercePage: FunctionComponent = () => { const handlelAddToCart = (product: Product) => { enqueueSnackbar(`eCommerce.addEcommerceItem()`, { variant: 'success' }) - eCommerce.addEcommerceItem([ + eCommerce.ecommerceAddToCart([ { ...product, quantity: 1 diff --git a/src/constants/track-event.constant.ts b/src/constants/track-event.constant.ts index 889aecc..8fc87bb 100644 --- a/src/constants/track-event.constant.ts +++ b/src/constants/track-event.constant.ts @@ -3,7 +3,8 @@ export enum TRACK_EVENT { CUSTOM_EVENT = 'trackEvent', GOAL = 'trackGoal', SEARCH = 'trackSiteSearch', - ADD_ECOMMERCE_ITEM = 'ecommerceAddToCart', + ECOMMERCE_ADD_TO_CART = 'ecommerceAddToCart', + ADD_ECOMMERCE_ITEM = 'addEcommerceItem', REMOVE_ECOMMERCE_ITEM = 'ecommerceAddToCart', ECOMMERCE_PRODUCT_DETAIL_VIEW = 'ecommerceProductDetailView', UPDATE_ECOMMERCE_CART = 'ecommerceCartUpdate', @@ -67,5 +68,5 @@ export enum TRACK_EVENT { SET_REQUEST_CONTENT_TYPE = 'setRequestContentType', ENABLE_JS_ERROR_TRACKING = 'enableJSErrorTracking', ERROR = 'trackError', - SET_TRACKING_SOURCE = 'setTrackingSource', + SET_TRACKING_SOURCE = 'setTrackingSource' } diff --git a/src/services/e-commerce/e-commerce.service.ts b/src/services/e-commerce/e-commerce.service.ts index 12c3277..e258bbd 100644 --- a/src/services/e-commerce/e-commerce.service.ts +++ b/src/services/e-commerce/e-commerce.service.ts @@ -2,9 +2,28 @@ import { TRACK_EVENT } from '../../constants/track-event.constant' import { PaqService } from '../paqService/paq.service' import { Product } from '../../interfaces/product' import { PaymentInformation } from '../../interfaces/payment' +/** + * @deprecated since version 1.3.1. Please use the newMethod instead. + */ +export function addEcommerceItem( + productSKU: string, + productName: string, + productCategory: string | string[], + productPrice: number, + productQuantity: number +) { + PaqService.push([ + TRACK_EVENT.ADD_ECOMMERCE_ITEM, + productSKU, + productName, + productCategory, + productPrice, + productQuantity + ]) +} -export function addEcommerceItem(products: Product[]) { - PaqService.push([TRACK_EVENT.ADD_ECOMMERCE_ITEM, products]) +export function ecommerceAddToCart(products: Product[]) { + PaqService.push([TRACK_EVENT.ECOMMERCE_ADD_TO_CART, products]) } export function removeEcommerceItem(products: Product[]) {