diff options
| author | Rafi Zadanly <zadanlyr@gmail.com> | 2023-06-03 11:16:32 +0700 |
|---|---|---|
| committer | Rafi Zadanly <zadanlyr@gmail.com> | 2023-06-03 11:16:32 +0700 |
| commit | 0ee7434188364dc230bbd034dc165a0f4850e3db (patch) | |
| tree | d68059fb394f89ac0ad2887b25d49fcb7fd0d8d6 /src/core | |
| parent | c89f620717483331534c4c8e7b1c9208799c2c11 (diff) | |
Add gtag event on product detail
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/utils/googleTag.js | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/core/utils/googleTag.js b/src/core/utils/googleTag.js new file mode 100644 index 00000000..9faea39e --- /dev/null +++ b/src/core/utils/googleTag.js @@ -0,0 +1,32 @@ +export const gtagAddToCart = (variant, quantity) => { + gtag('event', 'add_to_cart', { + currency: 'IDR', + value: variant.price.priceDiscount * quantity, + items: [ + { + item_id: variant.id, + item_name: variant.name, + discount: variant.price.price - variant.price.priceDiscount, + item_brand: variant.manufacture?.name, + item_variant: variant.code || variant.id, + price: variant.price.price, + quantity + } + ] + }) +} + +export const gtagViewItem = (variants) => { + let items = [] + for (const variant of variants) { + items.push({ + item_id: variant.id, + item_name: variant.parent.name, + discount: variant.price.price - variant.price.priceDiscount, + item_brand: variant.manufacture?.name, + item_variant: variant.code || variant.id, + price: variant.price.price + }) + } + gtag('event', 'view_item', { items }) +} |
