From bce0d508217b9b10b5324acbb20afbf63130286c Mon Sep 17 00:00:00 2001 From: gimenes Date: Mon, 6 Nov 2023 14:00:03 -0300 Subject: [PATCH 1/2] improve cart events --- components/Analytics.tsx | 14 +++--- components/product/AddToCartButton/common.tsx | 34 +++---------- components/product/AddToCartButton/linx.tsx | 13 +++-- .../product/AddToCartButton/shopify.tsx | 10 ++-- components/product/AddToCartButton/vnda.tsx | 13 +++-- components/product/AddToCartButton/vtex.tsx | 11 +++-- components/product/AddToCartButton/wake.tsx | 11 +++-- components/product/ProductInfo.tsx | 48 ++++++++++++++----- components/product/ProductShelf.tsx | 3 +- components/product/ProductShelfTabbed.tsx | 5 +- deno.json | 2 +- dev.ts | 4 ++ sdk/analytics.tsx | 4 +- 13 files changed, 95 insertions(+), 77 deletions(-) diff --git a/components/Analytics.tsx b/components/Analytics.tsx index 1b2a4854..32b99853 100644 --- a/components/Analytics.tsx +++ b/components/Analytics.tsx @@ -6,15 +6,15 @@ const snippet = (id: string, event: AnalyticsEvent) => { const element = document.getElementById(id); if (!element) { - console.warn( + return console.warn( `Could not find element ${id}. Click event will not be send. This will cause loss in analytics`, ); - } else { - element.addEventListener( - "click", - () => window.DECO.events.dispatch(event), - ); } + + element.addEventListener("click", () => { + console.log(JSON.stringify(event, null, 2)); + window.DECO.events.dispatch(event); + }); }; /** @@ -30,5 +30,5 @@ export const SendEventOnClick = ({ event, id }: { * This behavior is usefull for view_* events. */ export const SendEventOnLoad = ( - { event }: { event: E }, + { event }: { event: E; id?: string }, ) =>