diff options
| author | trisusilo <tri.susilo@altama.co.id> | 2024-04-29 07:10:20 +0000 |
|---|---|---|
| committer | trisusilo <tri.susilo@altama.co.id> | 2024-04-29 07:10:20 +0000 |
| commit | d169ea22f8823f1bd9a94614ae2529677e0688ab (patch) | |
| tree | ea9bf55f86cb8e210757a0cc746164184072ad95 | |
| parent | 1850e105ce6578465a015e395fa4c38544afdafe (diff) | |
| parent | 7da27cae381ad9cc6dfa1b4987cb0cc4e404c522 (diff) | |
Merged in agnes (pull request #137)
google tag
| -rw-r--r-- | src-migrate/modules/product-detail/components/ProductDetail.tsx | 6 | ||||
| -rw-r--r-- | src/core/utils/googleTag.js | 24 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src-migrate/modules/product-detail/components/ProductDetail.tsx b/src-migrate/modules/product-detail/components/ProductDetail.tsx index 3b1bdbea..bfdf5b43 100644 --- a/src-migrate/modules/product-detail/components/ProductDetail.tsx +++ b/src-migrate/modules/product-detail/components/ProductDetail.tsx @@ -23,6 +23,8 @@ import SimilarBottom from './SimilarBottom' import SimilarSide from './SimilarSide' import VariantList from './VariantList' +import { gtagProductDetail } from '@/core/utils/googleTag' + type Props = { product: IProductDetail } @@ -35,6 +37,10 @@ const ProductDetail = ({ product }: Props) => { const { setAskAdminUrl, askAdminUrl, activeVariantId } = useProductDetail() useEffect(() => { + gtagProductDetail(product); + },[product]) + + useEffect(() => { const createdAskUrl = whatsappUrl({ template: 'product', payload: { diff --git a/src/core/utils/googleTag.js b/src/core/utils/googleTag.js index cc6d1283..96a6bd2e 100644 --- a/src/core/utils/googleTag.js +++ b/src/core/utils/googleTag.js @@ -33,6 +33,20 @@ const sumTotal = (variants) => { } } +const mapProducts = (product) => { + const res = { + item_id: product.id, + item_name: product.name, + discount: product.lowest_price.price_discount || 0, + // index: 0, + item_brand: product.manufacture.name, + item_category: product.categories, + item_variant: product.variants, + price: product.lowest_price.price, + quantity: product.stock_total + } + return res +} export const gtagAddToCart = (variant, quantity) => { const param = { currency: 'IDR', @@ -77,3 +91,13 @@ export const gtagPurchase = (variants, shipping, transactionId) => { } gtag('event', 'purchase', param) } + +export const gtagProductDetail = (product) => { + const items = mapProducts(product) + const param = { + currency: 'IDR', + value: product.id, + items + } + gtag('event', 'view_item', param) +}
\ No newline at end of file |
