From a8f7921274ba460204babe5220e6e77d7ed097c9 Mon Sep 17 00:00:00 2001 From: vcua-mobify Date: Mon, 12 Sep 2022 17:50:47 -0700 Subject: [PATCH] Update PLP to send clickSearch and clickCategory activities --- .../app/commerce-api/einstein.js | 22 ++++++++++++++----- .../app/pages/product-list/index.jsx | 7 ++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/template-retail-react-app/app/commerce-api/einstein.js b/packages/template-retail-react-app/app/commerce-api/einstein.js index 96f190b139..9fe32dbbc7 100644 --- a/packages/template-retail-react-app/app/commerce-api/einstein.js +++ b/packages/template-retail-react-app/app/commerce-api/einstein.js @@ -108,12 +108,18 @@ class EinsteinAPI { /** * Tells the Einstein engine when a user clicks on a search result. **/ - async sendClickSearch(searchText, products, args) { + async sendClickSearch(searchText, product, args) { const endpoint = `/activities/${this.config.siteId}/clickSearch` const method = 'POST' + const {productId, sku = '', altId = '', altIdType = ''} = product const body = { searchText, - products, + product: { + id: productId, + sku, + altId, + altIdType + }, ...args } @@ -141,14 +147,20 @@ class EinsteinAPI { * Tells the Einstein engine when a user clicks a product from the category page. * Not meant to be used when the user clicks a category from the nav bar. **/ - async sendClickCategory(category, products, args) { + async sendClickCategory(category, product, args) { const endpoint = `/activities/${this.config.siteId}/clickCategory` const method = 'POST' + const {productId, sku = '', altId = '', altIdType = ''} = product const body = { category: { - id + id: category.id + }, + product: { + id: productId, + sku, + altId, + altIdType }, - products, ...args } diff --git a/packages/template-retail-react-app/app/pages/product-list/index.jsx b/packages/template-retail-react-app/app/pages/product-list/index.jsx index 407f913f4b..e54770b118 100644 --- a/packages/template-retail-react-app/app/pages/product-list/index.jsx +++ b/packages/template-retail-react-app/app/pages/product-list/index.jsx @@ -425,6 +425,13 @@ const ProductList = (props) => { product={productSearchItem} enableFavourite={true} isFavourite={isInWishlist} + onClick={() => { + if (searchQuery) { + einstein.sendClickSearch(searchQuery, productSearchItem) + } else if (category) { + einstein.sendClickCategory(category, productSearchItem) + } + }} onFavouriteToggle={(isFavourite) => { const action = isFavourite ? addItemToWishlist