Pular para o conteúdo principal

Events

The communication between the main page and the scripts is handled through events, ensuring a reactive and flexible integration where each component operates independently without direct calls.

  • Events Dispatched by the Store / Checkout: When significant changes occur—such as an update to the shopping cart—the store or checkout dispatches events (e.g., cart:update) to notify scripts that a change has occurred.
  • Events Dispatched by the Apps: Conversely, the scripts can emit events (like cart:validate) to report on the validity of the cart contents or to signal that additional actions might be required.

The listener always receives the current state at the time of the event. The listener signature is (state, event) => void, where event is the event name string. For nube.send, the second argument is optional: a function (state) => partialState; only the returned keys are merged into the current state.

This event-driven approach allows the application to respond in real-time to state changes, simplifying maintenance and enhancing scalability.

Events reference

EventDispatched byListen / SendDescription
page:loaded storeListenFired when the page is loaded and the SDK is ready to use.
checkout:ready checkoutListenFired when a new checkout page is loaded and ready.
checkout:success checkoutListenFired when checkout completes successfully.
config:set appSendSet initial script configuration.
cart:update storeListenFired when the cart content changes.
cart:view storeListenFired when the user views the cart.
cart:validate appSendSignal whether the cart content is valid (requires has_cart_validation: true).
cart:add appSendAdd an item to the cart.
cart:add:success storeListenFired when an item is successfully added; state.eventPayload has item context.
cart:add:fail storeListenFired when adding an item fails; state.eventPayload has context.
cart:remove appSendRemove an item from the cart.
cart:remove:success storeListenFired when an item is successfully removed.
cart:remove:fail storeListenFired when removing an item fails.
order:update checkoutListenFired when the order is completed (success page).
order:add:tracking_statuses appSendAdd tracking statuses to the order.
coupon:add appSendAdd a coupon to the cart.
coupon:add:success storeListenFired when a coupon is successfully added.
coupon:add:fail storeListenFired when adding a coupon fails.
coupon:remove appSendRemove a coupon from the cart.
coupon:remove:success storeListenFired when a coupon is successfully removed.
coupon:remove:fail storeListenFired when removing a coupon fails.
shipping:update checkoutListenFired when the shipping method changes.
shipping:select appSendChange the selected shipping option.
shipping:select:success checkoutListenFired when a shipping option is selected successfully.
shipping:select:fail checkoutListenFired when selecting a shipping option fails.
shipping:update:label appSendUpdate custom labels for shipping options.
customer:update storeListenFired when customer data changes.
payment:update checkoutListenFired when the payment method changes.
ui:slot:set appSendSet or clear the content of a UI slot.
location:updated storeListenFired when the page or visible content changes.
quickbuy:open storeListenFired when the quick buy modal is opened; state.eventPayload has product data.
quickbuy:close storeListenFired when the quick buy modal is closed; state.eventPayload has product data.
custom:*:* app / storeListen & SendCustom events (e.g. custom:modal:close). See Custom events .
Where events run

Some events are only available in checkout: cart:validate, coupon:add, coupon:remove, shipping:update, shipping:select, shipping:update:label, payment:update, order:add:tracking_statuses. Others are only available in storefront: cart:view, quickbuy:open, quickbuy:close. All other events work in both contexts (or depend on the page). Each restricted event is marked on its respective page.

Event groups

  • Page & Lifecycle page:loaded, checkout:ready, checkout:success, config:set, location:updated
  • Cart cart:update, cart:view, cart:validate, cart:add, cart:remove and their success/fail variants
  • Order order:update, order:add:tracking_statuses
  • Coupon coupon:add, coupon:remove and their success/fail variants
  • Shipping shipping:update, shipping:select, shipping:update:label and their success/fail variants
  • Customer & Payment customer:update, payment:update
  • UI & Custom ui:slot:set, quickbuy:open, quickbuy:close, custom events