Events
The widget exposes an event-driven API. Attach listeners in your application and keep business logic there.
Register and remove listeners
const onAddToCart = (data: { products: Array<{ productId: string; variantId?: string }> }) => {
console.log("add_to_cart", data.products);
};
widget.on("add_to_cart", onAddToCart);
// Later, cleanup:
widget.off("add_to_cart", onAddToCart);
Event reference
ready
Fired when the widget is ready to use.
add_to_cart
Fired when the widget requests adding products to cart.
Payload shape:
Example:
widget.on("add_to_cart", async (data) => {
for (const product of data.products) {
// Resolve variant if needed, then call your cart API/action
await addToCartInYourApp(product);
}
});
send_to_checkout
Fired when user should be redirected to checkout.
error
Fired when the widget reports an error.