From 87dab97621e35ba908b1c69344cf955556875e91 Mon Sep 17 00:00:00 2001 From: William Chong Date: Thu, 14 Nov 2024 19:29:46 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=88=20Add=20more=20gre=20events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/store/index.vue | 3 +- src/util/EventLogger.js | 64 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/pages/store/index.vue b/src/pages/store/index.vue index 919feee99..15c09c576 100644 --- a/src/pages/store/index.vue +++ b/src/pages/store/index.vue @@ -1082,7 +1082,7 @@ export default { name: item.title, price: item.minPrice, })), - search_term: this.searchQuery || this.selectedTagTitle, + search_term: this.searchQuery || undefined, isNFTBook: true, }); }, @@ -1300,7 +1300,6 @@ export default { price: item.minPrice, currency: 'USD', })), - search_term: tag.name, isNFTBook: true, }); }, diff --git a/src/util/EventLogger.js b/src/util/EventLogger.js index e96eeb007..b9fd3d703 100644 --- a/src/util/EventLogger.js +++ b/src/util/EventLogger.js @@ -240,7 +240,7 @@ export function logPurchaseFlowEvent( }); } } - if (vue.$fb && FACEBOOK_PIXEL_ID) { + if (window.fbq && !IS_TESTNET) { const eventNameMapping = { view_item: 'ViewContent', begin_checkout: 'InitiateCheckout', @@ -280,6 +280,68 @@ export function logPurchaseFlowEvent( ); } } + if (vue.$gre) { + const productDetails = items?.map(i => { + let itemId = i.productId || i.collectionId || i.classId; + if (i.priceIndex !== undefined) { + itemId = `${itemId}-${i.priceIndex}`; + } + return { + product: { id: itemId }, + quantity: i.quantity || 1, + }; + }); + switch (event) { + case 'view_item_list': { + if (otherPayload.search_term) { + vue.$gre.logEvent('search', { + searchQuery: otherPayload.search_term, + pageCategories: ['eBook'], + productDetails, + }); + } else if (otherPayload.list_id !== 'listing') { + vue.$gre.logEvent('category-page-view', { + pageCategories: [`eBook > ${otherPayload.list_id}`], + productDetails, + }); + } + break; + } + case 'view_item': { + vue.$gre.logEvent('detail-page-view', { + productDetails, + }); + break; + } + case 'add_to_cart': { + vue.$gre.logEvent('add-to-cart', { + cartId: paymentId, + productDetails, + }); + break; + } + case 'view_cart': { + vue.$gre.logEvent('shopping-cart-view', { + cartId: paymentId, + productDetails, + }); + break; + } + case 'purchase': { + vue.$gre.logEvent('purchase-complete', { + cartId: paymentId, + productDetails, + purchaseTransaction: { + revenue: price, + currencyCode: currency, + }, + }); + break; + } + default: + break; + } + } if (vue.$crisp) { vue.$crisp.push([ 'set',