Settings hooks (recommended)
The simplest and most reliable approach is to define callback functions directly inwindow.molinSettings. Because this object is defined before the widget script loads, the onReady hook is guaranteed to fire.
Available hooks
Settings hooks can be combined with other
molinSettings properties like hidden or userData in the same object.Custom cart integration
Molin drives the cart out of the box on Shopify, Shoper, Shoprenter, and UNAS. On any other platform, register cart handlers inwindow.molinSettings and Molin uses yours instead: the add-to-cart button appears on product cards automatically, and the assistant can read and change the cart during a conversation.
handleAddToCart turns the integration on and takes precedence over Molin’s built-in platform detection. Add the others to widen what the assistant is allowed to do, and it’s offered only what you registered.
onAddToCart notification. The product card button shows a spinner while your promise is pending, a checkmark when it resolves, and an error indicator when it rejects or doesn’t settle within 30 seconds.
Address lines by the lineId you returned from handleGetCart, not by product ID, because one product can occupy several cart lines.
Your
handleAddToCart may be called several times in a row for a single request, once per unit, so make it safe to repeat. Registering handleSetCartQuantity lets the assistant set a line already
in the cart in one call instead.When
handleAddToCart resolves, Molin pushes the standard GA4 add_to_cart ecommerce event and fires molin:add-to-cart, so don’t track your own add_to_cart inside the handler or it will be
double-counted.Window events (alternative)
The widget also dispatches standardCustomEvent events on the window object. Use this approach if you need multiple independent listeners for the same event, or if you prefer the DOM event API.
Available events
molin:ready
Fired once when the widget has fully loaded its configuration and rendered for the first time.
If your script loads after the widget, the This race condition does not exist with the settings hooks approach above, which is why it is recommended.
molin:ready event may have already fired. In that case, check if window.Molin already exists as a fallback:molin:chat-open
Fired whenever the chat window is opened, whether by the user clicking the bubble, a popup click, the floating input, a programmatic call to openChat(), or a restored session on mobile.
molin:chat-close
Fired whenever the chat window is closed, whether by the user clicking the close button, toggling the bubble, or a programmatic call to closeChat().
molin:message-sent
Fired when the user sends a message in the chat.
molin:link-click
Fired when the user clicks a link inside the chat conversation.
molin:add-to-cart
Fired after the product was successfully added to the cart, either by Molin’s built-in integration on Shopify, Shoper, Shoprenter, and UNAS stores (where the button is enabled automatically), or by your own handleAddToCart handler on other platforms. Use the event to refresh your theme’s cart drawer or cart count badge, since themes usually only update their cart UI in response to their own add-to-cart flows.