From 0ee7434188364dc230bbd034dc165a0f4850e3db Mon Sep 17 00:00:00 2001
From: Rafi Zadanly <zadanlyr@gmail.com>
Date: Sat, 3 Jun 2023 11:16:32 +0700
Subject: Add gtag event on product detail

---
 src/lib/product/components/Product/ProductDesktop.jsx | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

(limited to 'src/lib/product/components/Product/ProductDesktop.jsx')

diff --git a/src/lib/product/components/Product/ProductDesktop.jsx b/src/lib/product/components/Product/ProductDesktop.jsx
index 75b37b9d..4a584761 100644
--- a/src/lib/product/components/Product/ProductDesktop.jsx
+++ b/src/lib/product/components/Product/ProductDesktop.jsx
@@ -14,6 +14,7 @@ import BottomPopup from '@/core/components/elements/Popup/BottomPopup'
 import ProductCard from '../ProductCard'
 import productSimilarApi from '../../api/productSimilarApi'
 import whatsappUrl from '@/core/utils/whatsappUrl'
+import { gtagAddToCart } from '@/core/utils/googleTag'
 
 const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
   const router = useRouter()
@@ -52,11 +53,12 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
     return isValid
   }
 
-  const handleAddToCart = (variantId) => {
-    const quantity = variantQuantityRefs.current[variantId].value
+  const handleAddToCart = (variant) => {
+    const quantity = variantQuantityRefs.current[variant.id].value
     if (!validQuantity(quantity)) return
+    gtagAddToCart(variant, quantity)
     updateItemCart({
-      productId: variantId,
+      productId: variant.id,
       quantity,
       selected: true
     })
@@ -247,14 +249,14 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                 />
                 <button
                   type='button'
-                  onClick={() => handleAddToCart(product.variants[0].id)}
+                  onClick={() => handleAddToCart(product.variants[0])}
                   className='flex-1 py-2 btn-yellow'
                 >
                   Keranjang
                 </button>
                 <button
                   type='button'
-                  onClick={() => handleBuy(product.variants[0].id)}
+                  onClick={() => handleBuy(product.variants[0])}
                   className='flex-1 py-2 btn-solid-red'
                 >
                   Beli
@@ -345,7 +347,7 @@ const ProductDesktop = ({ product, wishlist, toggleWishlist }) => {
                       <td className='flex gap-x-3'>
                         <button
                           type='button'
-                          onClick={() => handleAddToCart(variant.id)}
+                          onClick={() => handleAddToCart(variant)}
                           className='flex-1 py-2 btn-yellow'
                         >
                           Keranjang
-- 
cgit v1.2.3

