Skip to content
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

Merged
merged 24 commits into from
Sep 22, 2022
Merged

Add new activities to Einstein API #714

merged 24 commits into from
Sep 22, 2022

Conversation

vcua-mobify
Copy link
Contributor

@vcua-mobify vcua-mobify commented Sep 12, 2022

This PR adds support for the following additional activities to our Einstein API:

  • viewPage
  • viewSearch
  • clickSearch
  • viewCategory
  • clickCategory
  • beginCheckout

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

  • Verify you see a viewProduct activity sent when viewing a product page
  • Verify you see a viewCategory activity when viewing a category page
  • Verify you see a viewSearch activity page when viewing search results
  • Verify you see a clickCategory activity when you click a product tile on a category page
  • Verify you see a clickSearch activity when you click a product tile on a search page
  • Verify you see a beginCheckout activity when you first visit the checkout page
  • Verify you see a viewPage activity on other pages (Home page, login page, account page, etc.)

@vcua-mobify vcua-mobify added the wip Work in process label Sep 12, 2022
@vcua-mobify vcua-mobify requested a review from a team as a code owner September 12, 2022 23:22
@vcua-mobify vcua-mobify changed the title [WIP] Einstein API update Add new activities to Einstein API Sep 15, 2022
@vcua-mobify vcua-mobify added ready for review PR is ready to be reviewed and removed wip Work in process labels Sep 15, 2022
Comment on lines +97 to +121
/**
* 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)
}
Copy link
Collaborator

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.

Comment on lines +22 to +39
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)
},
Copy link
Collaborator

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)
Copy link
Collaborator

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)

@vcua-mobify vcua-mobify requested a review from bendvc September 19, 2022 18:37
@vcua-mobify
Copy link
Contributor Author

@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.

Copy link
Collaborator

@shethj shethj left a 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.

@vcua-mobify vcua-mobify merged commit c5db22c into develop Sep 22, 2022
@adamraya adamraya mentioned this pull request Oct 6, 2022
12 tasks
@wjhsf wjhsf deleted the einstein-api-update branch March 17, 2023 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants