Skip to content

Commit 3db7729

Browse files
activity event tracking for 1cc (#3627)
1 parent 5144503 commit 3db7729

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

packages/template-retail-react-app/app/hooks/use-einstein.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export class EinsteinAPI {
178178
namespace: 'useEinstein.einsteinFetch',
179179
additionalProperties: {error: error}
180180
})
181+
return {}
181182
}
182183

183184
if (!response?.ok) {
@@ -342,15 +343,16 @@ export class EinsteinAPI {
342343
/**
343344
* Tells the Einstein engine when a user starts the checkout process.
344345
**/
345-
async sendBeginCheckout(basket, args) {
346+
async sendBeginCheckout(basket, args = {}) {
346347
const endpoint = `/activities/${this.siteId}/beginCheckout`
347348
const method = 'POST'
348349
const products = basket.productItems.map((item) => this._constructEinsteinItem(item))
349350
const subTotal = basket.productSubTotal
350351
const body = {
351352
products: products,
352353
amount: subTotal,
353-
...args
354+
checkoutType: 'traditional', // Default to traditional for backward compatibility
355+
...args // Allow override (e.g., checkoutType: 'one-click')
354356
}
355357

356358
return this.einsteinFetch(endpoint, method, body)
@@ -360,14 +362,15 @@ export class EinsteinAPI {
360362
* Tells the Einstein engine when a user reaches the given step during checkout.
361363
* https://developer.salesforce.com/docs/commerce/einstein-api/references#einstein-recommendations:Summary
362364
**/
363-
async sendCheckoutStep(stepName, stepNumber, basket, args) {
365+
async sendCheckoutStep(stepName, stepNumber, basket, args = {}) {
364366
const endpoint = `/activities/${this.siteId}/checkoutStep`
365367
const method = 'POST'
366368
const body = {
367369
stepName,
368370
stepNumber,
369371
basketId: basket.basketId,
370-
...args
372+
checkoutType: 'traditional', // Default to traditional for backward compatibility
373+
...args // Allow override (e.g., checkoutType: 'one-click')
371374
}
372375

373376
return this.einsteinFetch(endpoint, method, body)

packages/template-retail-react-app/app/pages/checkout-one-click/util/checkout-context.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,18 @@ export const CheckoutProvider = ({children}) => {
8080
// Run this once when checkout begins
8181
useEffect(() => {
8282
if (basket?.productItems) {
83-
einstein.sendBeginCheckout(basket)
83+
einstein.sendBeginCheckout(basket, {
84+
checkoutType: 'one-click'
85+
})
8486
}
8587
}, [])
8688

8789
// Run this every time checkout steps change
8890
useEffect(() => {
8991
if (step != undefined) {
90-
einstein.sendCheckoutStep(getCheckoutStepName(step), step, basket)
92+
einstein.sendCheckoutStep(getCheckoutStepName(step), step, basket, {
93+
checkoutType: 'one-click'
94+
})
9195
}
9296
}, [step])
9397

0 commit comments

Comments
 (0)