Skip to main content

Buyer Journey

The API for interacting with the buyer journey.

The base API object provided to purchase extension targets.

Anchor to buyerJourney
buyerJourney
required

Provides details on the buyer's progression through the checkout.

Refer to buyer journey examples for more information.

Anchor to useBuyerJourney
useBuyerJourney()

Returns the buyerJourney details on buyer progression in checkout.

BuyerJourney

Provides details on the buyer's progression through the checkout.

activeStep
< | undefined>

What step of checkout the buyer is currently on.

completed
<boolean>

This subscribable value will be true if the buyer completed submitting their order.

For example, when viewing the Order status page after submitting payment, the buyer will have completed their order.

intercept
(interceptor: ) => Promise<() => void>

Installs a function for intercepting and preventing progress on checkout.

This returns a promise that resolves to a teardown function. Calling the teardown function will remove the interceptor.

To block checkout progress, you must set the block_progress capability in your extension's configuration.

If you do, then you're expected to inform the buyer why navigation was blocked, either by passing validation errors to the checkout UI or rendering the errors in your extension.

It is good practice to show a warning in the checkout editor when the merchant has not given permission for your extension to block checkout progress.

steps
<[]>

All possible steps a buyer can take to complete the checkout. These steps may vary depending on the type of checkout or the shop's configuration.

Anchor to useBuyerJourneyCompleted
useBuyerJourneyCompleted()

Returns true if the buyer completed submitting their order. For example, when viewing the Order status page after submitting payment, the buyer will have completed their order.

false | true

Installs a function for intercepting and preventing progress on checkout. To block checkout progress, you must set the block_progress capability in your extension's configuration. If you do, then you're expected to inform the buyer why navigation was blocked, either by passing validation errors to the checkout UI or rendering the errors in your extension. useBuyerJourneyIntercept() should be called at the top level of the extension, not within an embedded or child component, to avoid errors should the child component get destroyed. It is good practice to show a warning in the checkout editor when the merchant has not given permission for your extension to block checkout progress.

Anchor to interceptor
interceptor
required

Anchor to useBuyerJourneySteps
useBuyerJourneySteps()

Returns all possible steps a buyer can take to complete the checkout. These steps may vary depending on the type of checkout or the shop's configuration.

[]

Anchor to useBuyerJourneyActiveStep
useBuyerJourneyActiveStep()

Returns the buyer journey step that the buyer is currently on.

| undefined
Examples

Preact

import '@shopify/ui-extensions/preact';
import {render} from 'preact';

import {
useBuyerJourneyIntercept,
useExtensionEditor,
useExtensionCapability,
} from '@shopify/ui-extensions/checkout/preact';

export default function extension() {
render(<Extension />, document.body);
}

function Extension() {
const editorType = useExtensionEditor()?.type;
const blockProgressGranted =
useExtensionCapability('block_progress');

useBuyerJourneyIntercept(
({canBlockProgress}) => {
return canBlockProgress &&
shopify.shippingAddress.value
?.countryCode &&
shopify.shippingAddress.value
.countryCode !== 'CA'
? {
behavior: 'block',
reason: 'Invalid shipping country',
errors: [
{
message:
'Sorry, we can only ship to Canada',
// Show an error underneath the country code field
target:
'$.cart.deliveryGroups[0].deliveryAddress.countryCode',
},
{
// In addition, show an error at the page level
message:
'Please use a different address.',
},
],
}
: {
behavior: 'allow',
};
},
);

return (
<>
{editorType === 'checkout' &&
!blockProgressGranted ? (
<s-banner
tone="warning"
heading="This app may be misconfigured"
>
To allow this app to block checkout,
enable this behavior in "Checkout
behavior" settings.
</s-banner>
) : null}
</>
);
}
Was this page helpful?