summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/utils/googleTag.js32
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 })
+}