Events

CODE
next.on('order.paid', (data, event) => {
  console.log(data.ref_id);
});

next.on('*', (data, event) => {}); // every event

Names

Each name is namespace.action, as in Next Commerce webhooks:

  • namespace: the thing that changed (cart, checkout, order, …)
  • action: what happened to it (added, started, paid, …)

Two to know:

  • user.created: the user the store keeps for marketing, saved with the Cart the cart.abandoned webhook sends later.
  • order.paid: once per order. On the checkout when paid at once, else on the page after the payment gateway.

The envelope

event is shaped like a webhook:

FieldValue
event_idUnique, a UUID v4 as 32 hex digits
event_typeThe name, such as 'order.paid'
objectThe namespace, such as 'order'
dataSame as data
created_atISO time
session_idThe campaign session, a UUID v4 as 32 hex digits
sdk_versionThe SDK version

What data holds

data is the object the namespace names.

Eventsdata
selector.*The Selector; a bundle or offer selector lists every option in options
cart.*The Cart; cart.added and cart.removed add changes, the one change made
coupon.*The code
checkout.*The Checkout (see below)
user.*The User
address.*The Address, with its type
shipping.selectedThe ShippingMethod
payment.*The Payment; a payment at a gateway adds the order's ref_id
order.*The Order
upsell.*The Upsell
promotion.*The Promotion
sdk.errorA Failure (code, message, status, decline_code) and the action that failed
*.failedCarries the Failure as error

The Checkout has:

  • id: the same across steps, reloads and a return from a payment gateway
  • step
  • cart: the same Cart as cart.*
  • user, shipping_address, billing_same_as_shipping, billing_address, payment_method: once the shopper has entered them

Late listeners miss nothing

  • Events come in order, once each.

  • next.on first replays the events of that name this page already sent, then each new one.

  • The page keeps its last 100 events. Past that it drops, in order:

    1. the oldest price updates (cart.updated, cart.calculating, cart.calculated, selector.pricing, selector.priced)
    2. the SDK's internal events
    3. the rest
  • sdk.ready and the newest event always stay. ready is the same event as sdk.ready.

Snapshot

next.snapshot() returns what the page shows now, as the same objects the events carry:

  • campaign, cart, selectors
  • checkout, on a checkout page
  • order, once one has loaded

sdk.ready carries the snapshot at that moment.

Errors

SituationEvents
The SDK or the API could not do a stepsdk.error
…and it changes what the shopper seesthen checkout.failed, upsell.failed, or coupon.denied with reason: 'check_failed'
A declined card or upsell, or back from a gateway unpaidpayment.failed only (not an SDK failure)

Event Reference

  • A group whose events follow a lifecycle starts with a page that draws it, such as the cart's. It lists the events it covers, including other namespaces that come with it.
  • Each event has its own page with its fields and an example, generated from EventMap in src/engine/events.ts.
  • user and address events are checked when the shopper leaves a field (its change), not on each key.

SDK

EventWhen
sdk.readyOnce a page, when the campaign is in: at once from a copy saved in the last 10 minutes, else when the API answers.
sdk.errorA step failed.

Selectors

EventWhen
selector.viewedOnce a page, when half of the selector is on screen, with the option it picked: from ?forceBundleId, the cart, data-next-selected, else its first option.
selector.selectedThe shopper picked another option, or switched a toggle on.
selector.updatedThe picked option's quantity or one of its slots changed.
selector.deselectedA toggle is switched off, or its line left the cart.
selector.pricingPricing the options that have no price yet starts; a toggle's line while it is off.
selector.pricedEvery option has a price.

Carts

EventWhen
cart.updatedLines, coupons or shipping changed, at once, before the server prices them.
cart.calculatingPricing starts; once for a burst of changes.
cart.calculatedServer totals arrived.
cart.addedPackages one change added, after its cart.updated.
cart.removedPackages one change removed, after its cart.updated.
shipping.selectedThe shipping method changed, right after the change's cart.updated, without prices; they come with cart.calculated as shipping_method.

Coupons

EventWhen
coupon.appliedA code takes money off and is on the cart.
coupon.removedA code was taken off the cart.
coupon.deniedA code is not applied.

Checkout

EventWhen
checkout.startedOnce per checkout, when its form is bound and the cart has lines, or when the cart first gets lines after that; the steps of a multi-step checkout, a reload and a return from a payment gateway keep the same checkout.
user.createdOnce per checkout, after checkout.started, when the store saves the shopper with a new Open Cart: what data-next-lead asks for is in (by default a first and last name and a valid email), checked when the shopper leaves a field they changed.
user.updatedThe shopper's details changed after user.created and are still valid.
address.enteredOnce per type per checkout, when that address is valid: every field its country requires is filled and valid, and so is each optional one filled.
address.updatedThe address changed after address.entered and is still valid.
address.autofilledThe shopper picked an address suggestion under line 1, and it filled these fields.
payment.selectedThe shopper changed the payment method, after checkout.started.
checkout.continuedA step of a multi-step checkout passed its checks; the next step's page opens.
checkout.submittedA submit passed its checks (the fields, then the card tokenized) and the order is being sent.
checkout.invalidA submit, or a step of a multi-step checkout, did not pass its checks; nothing is sent.
checkout.failedThe order could not be placed: refused, or the request failed.
checkout.completedThe checkout's order is paid; once per checkout.

Payments

EventWhen
payment.redirectedThe shopper is about to leave for the payment gateway (PayPal, 3-D Secure, …) to pay the order ref_id.
payment.failedA payment was not taken: a card declined on the checkout, the shopper back from a gateway unpaid, or an upsell declined.

Orders

EventWhen
order.createdThe store created the order, on the checkout: paid when it was paid at once, else payment.redirected follows and the shopper pays at the gateway.
order.loadedA page after the checkout loaded the order; on every such page.
order.paidThe order is paid, once per order in this browser: on the checkout after order.created when it was paid at once, else after order.loaded on the first page that loads it paid.
order.updatedAn upsell was added to the order, right after upsell.accepted.

Upsells

EventWhen
upsell.viewedOnce per offer, when half of it is on screen.
upsell.acceptedThe offer was added to the order.
upsell.skippedThe shopper went on without the offer.
upsell.failedAdding the offer failed: refused, or the order does not have it.

Promotions

EventWhen
promotion.viewedThe promotion is on screen: the popup opened, or half of a marked element is visible.
promotion.clickedThe promotion was clicked, before its action runs: an apply-coupon button then applies its code.
promotion.closedThe popup closed; once for each promotion.viewed of a popup, unless the page removed it.

0.4.x names

0.4.x names still work, with the payload 0.4.43 sent and at the same moment: cart:updated, cart:item-added, bundle:selection-changed, shipping:method-changed, coupon:validation-failed, exit-intent:*, campaign:loaded, checkout:started, order:completed, upsell:*, payment:error and the rest in src/compat/.

  • A 0.4.x name reaches only listeners added before the event. Exceptions, which 0.4.x pages listen for late: campaign:loaded, checkout:started, and a few more.
  • checkout:started comes once a page; checkout.started once per checkout.
  • fomo:* and profile:* are accepted and never fire; the SDK no longer has those features.
  • Any other name logs a warning and never fires.
  • DOM events kept for page scripts: next:initialized, next:ready (on window) and next:prospect-cart-created (on the checkout form).

Analytics

Tracking events have a listener of their own: next.analytics.on. They carry the same objects as these events, in the same envelope plus a context. See the Tracking events, How analytics works, and the Destinations that get them: GTM, GA4, the Meta pixel and any other vendor.