-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add new activities to Einstein API #714
Conversation
3097e3d
to
a8f7921
Compare
packages/template-retail-react-app/app/commerce-api/einstein.js
Outdated
Show resolved
Hide resolved
/** | ||
* Tells the Einstein engine when a user views search results. | ||
**/ | ||
async sendViewSearch(searchText, searchResults, args) { | ||
const endpoint = `/activities/${this.config.siteId}/viewSearch` | ||
const method = 'POST' | ||
|
||
const products = searchResults.hits.map((product) => { | ||
const {productId, sku = '', altId = '', altIdType = ''} = product | ||
return { | ||
id: productId, | ||
sku, | ||
altId, | ||
altIdType | ||
} | ||
}) | ||
|
||
const body = { | ||
searchText, | ||
products, | ||
...args | ||
} | ||
|
||
return this.einsteinFetch(endpoint, method, body) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No action required on this comment. But I wanted to make sure that you notice the commonalities between all these 'send' functions. There is probably room to DRY things up, but I don't expect this to be done at the moment as this Einstein work at some point will be removed from the template. It would be nice to hear your thoughts on what we might do in the future to make things more upgradable.
async sendViewSearch(...args) { | ||
return api.einstein.sendViewSearch(...args) | ||
}, | ||
async sendClickSearch(...args) { | ||
return api.einstein.sendClickSearch(...args) | ||
}, | ||
async sendViewCategory(...args) { | ||
return api.einstein.sendViewCategory(...args) | ||
}, | ||
async sendClickCategory(...args) { | ||
return api.einstein.sendClickCategory(...args) | ||
}, | ||
async sendViewPage(...args) { | ||
return api.einstein.sendViewPage(...args) | ||
}, | ||
async sendBeginCheckout(...args) { | ||
return api.einstein.sendBeginCheckout(...args) | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, if you squint, all these lines look the same. This is probably something to DRY up at some point. If you are feeling proactive, start a 1-pager on how we can look into refactoring this Einstein stuff.
// Run this once when checkout begins | ||
useEffect(() => { | ||
if (basket && basket.productItems) { | ||
einstein.sendBeginCheckout(basket) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know how many events einstein supports? I'm curious if the pattern we have where the client has a function for each event will scale. Maybe we need to investigate an api that looks similar to einstein.send(einsteinEvents.beginCheckout, args)
…oud/pwa-kit into einstein-api-update
packages/template-retail-react-app/app/pages/product-list/index.jsx
Outdated
Show resolved
Hide resolved
@bendvc I've added a new checkoutStep activity to the set of Einstein activities this API supports. To facilitate sending checkout step information, I also did a small refactor in the checkout context and assigned constants to the different checkout steps. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just that I think we can also extract the endpoints and methods for all the event functions out in one spot. But we can work on that when we extract einstein work into the SDK and work on DRY-ing out stuff.
This PR adds support for the following additional activities to our Einstein API:
It also updates the existing Einstein API activites to send additional data required by Reports and Dashboards.
How to test:
Test environment: https://scaffold-pwa-bjnl-prd.mobify-storefront.com/
Go to the above test environment and open the network tab
Navigate around the store