Skip to content

Commit

Permalink
Update PLP to send clickSearch and clickCategory activities
Browse files Browse the repository at this point in the history
  • Loading branch information
vcua-mobify committed Sep 13, 2022
1 parent df01004 commit a8f7921
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/template-retail-react-app/app/commerce-api/einstein.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a8f7921

Please sign in to comment.