Events and callbacks
One callback receives everything the widget has to tell your page. Use it to react to a finished scan, a cart change or a checkout, and to hand the shopper on to a screen of your own.
Events and callback
Your callback receives { event, data } for each of the events below.
Supported callback events
- closed: user closed the widget UI. data: {}
- minimized: user minimized the widget UI (float mode only). data: {}
- checkout: user clicked checkout from within the widget. data: CheckoutPayload
- cartItemAdded: an item was added or its quantity was increased. data: CartItemChangedPayload
- cartItemRemoved: an item was removed or its quantity was decreased. data: CartItemChangedPayload
- scanCompleted: scan completed and produced a batch id. data: { batch_id }
- wheelRewardWon: the shopper won a reward on Spin the Wheel. Sent once, after the wheel stops. data: WheelRewardWonPayload
Recommended handler pattern
function onWidgetMessage(message) {
switch (message.event) {
case 'checkout':
// message.data: { total_quantity, total_amount, currency, checkout_items, user? }
// `user` is { id?, name?, firstName?, lastName?, email? } when the widget
// has a profile on hand (collected before scan or supplied via config.user),
// otherwise omitted entirely.
break;
case 'cartItemAdded':
case 'cartItemRemoved':
// message.data: { total_quantity, changed_item, checkout_items }
break;
case 'scanCompleted':
// message.data: { batch_id }
break;
case 'wheelRewardWon':
// message.data: { reward_id, type, code, label, value, currency,
// min_order_amount, expires_at, instructions, redemption_authority }
// Show the code or pre-fill it at checkout. Never create a discount from it.
break;
case 'minimized':
case 'closed':
break;
default:
// Future-proofing: ignore unknown events
break;
}
}
Example payloads
checkout
{
"event": "checkout",
"data": {
"total_quantity": 2,
"total_amount": 12800,
"currency": "NGN",
"checkout_items": [
{
"product_id": 123,
"product_name": "Name",
"quantity": 2,
"brand_name": "Brand",
"sku": "SKU-123",
"image_url": "https://example.com/image.jpg",
"stock_level": 10,
"skin_analysis_batch_id": "a1B2c3D4e5",
"product_usage_routine_id": 88123
}
],
"widget_attribution_id": "0f6c2a9e-1d3b-4f7a-8c55-6e2b9d4a7f10",
"user": {
"id": "user-123",
"firstName": "Jane",
"lastName": "Doe",
"email": "[email protected]"
},
"wheel_reward": {
"reward_id": "9b1f0c2e-5d4a-4c1e-9a77-2f3c8d6e1a40",
"claim_token": "...",
"redemption_authority": "shopify"
}
}
}
Each item's skin_analysis_batch_id and product_usage_routine_id name the scan and the recommendation it came from. Keep them on the cart line through to the paid order, and report the order to have it credited to the scan. See Connect any store.
user is included when the widget has a profile on hand — either collected before the scan (contact step) or supplied via config.user. It is omitted entirely when nothing is known, so you can distinguish "no profile" from "anonymous". All fields inside user are optional.
wheel_reward is included when the shopper has an unused Spin the Wheel reward. Its claim_token is for the Oyster Shopify app and WooCommerce plugin, which apply the code for you. It does not carry the code: a checkout of your own should take the code from wheelRewardWon. A checkout with intent: "wheel_reward" and an empty cart is the shopper claiming a free-item reward.
welcome_offer ({ "code": "WELCOME10", "percent": 10 }) is included when you turn on a welcome offer in Oyster and this shopper gets it. The code is the one you created in your own store: apply it at your checkout, which decides who may use it. It is never sent together with wheel_reward.
cartItemAdded (payload shape is identical for cartItemRemoved)
Tip: checkout_items can be an empty array if the widget doesn’t yet have inventory-backed product IDs for the items in the cart.
{
"event": "cartItemAdded",
"data": {
"total_quantity": 1,
"changed_item": {
"product_id": 123,
"product_name": "Name",
"quantity": 1,
"brand_name": "Brand",
"sku": null,
"image_url": null,
"stock_level": null
},
"checkout_items": []
}
}
scanCompleted
{
"event": "scanCompleted",
"data": {
"batch_id": "batch_abc123"
}
}
wheelRewardWon
{
"event": "wheelRewardWon",
"data": {
"reward_id": "9b1f0c2e-5d4a-4c1e-9a77-2f3c8d6e1a40",
"type": "percentage_discount",
"code": "WHEEL-7QK2M9XWD4H8RZ3PLT6NVB5CJ1GYEA0S",
"label": "10% off",
"value": 10,
"currency": "NGN",
"min_order_amount": null,
"expires_at": "2026-11-26T09:14:22+00:00",
"instructions": "Use this code at checkout.",
"redemption_authority": "shopify"
}
}
type is one of percentage_discount, fixed_discount, free_item, free_delivery or free_scan. redemption_authority names the checkout the code was issued for: shopify, woocommerce, store for a checkout you registered yourself, or oyster for Oyster's own checkout.