Skip to main content

Events

The SDK reports every step of the purchase flow as:
  1. DOM custom events — bubble up from each <khaime-*> component, composed across Shadow DOM. Listen with addEventListener.
  2. SDK callbacks — registered via sdk.on({ … }). Easier when you’ve initialized the SDK programmatically.
Both fire for the same underlying action. Pick whichever fits your integration.

Two ways to listen

Every event detail includes timestamp (ms since epoch) and merchantId.

Purchase-flow events

khaime:product-click

Fired when a customer clicks a product card or tile.
Callback: onProductClick(product)

khaime:add-to-cart

Fired when a customer adds an item to the cart.
Callback: onAddToCart(product, quantity)

khaime:cart-updated

Fired on every cart mutation — add, remove, quantity change, clear, or hydrate from storage.
Callback: onCartUpdated(items, action) Use this to update a header badge, drawer count, or analytics.

khaime:cart-open / khaime:cart-close

Fired when the cart drawer (or cart page) opens or closes. Callbacks: onCartOpen(), onCartClose()

khaime:currency-change

Fired when the customer picks a different currency from the switcher.
Callback: onCurrencyChange(newCurrency)

khaime:checkout-init

Fired right after the SDK creates a checkout session (before the payment modal opens).
Callback: onCheckoutInit(sessionToken) Use this to log checkout starts for funnel analysis.

khaime:payment-success

Fired after the customer’s payment is confirmed.
Callback: onPaymentSuccess(result)
This event confirms the payment UI completed — not that the charge settled. Always verify via a webhook before fulfilling the order.

khaime:payment-error

Fired when the payment fails (declined card, expired session, gateway error, etc.).
Callback: onPaymentError(error)

Full callback signature

All purchase-related callbacks accepted by sdk.on(…):
Callbacks are additive — calling sdk.on(...) multiple times merges into the existing handler map (later calls override same-named keys).

Analytics example

Wire every purchase step into your analytics tool:

See also