Skip to main content
The Molin AI widget notifies your website at key moments in its lifecycle. You can use these hooks to trigger custom logic such as initializing integrations, adjusting page layout, or tracking analytics. The simplest and most reliable approach is to define callback functions directly in window.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 in window.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.
Every handler is awaited, unlike the fire-and-forget 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.
The assistant changes the cart without asking the customer to confirm. Reject in your handler when a change shouldn’t be allowed, and the customer is told why instead of the change going through.
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 standard CustomEvent 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 molin:ready event may have already fired. In that case, check if window.Molin already exists as a fallback:
This race condition does not exist with the settings hooks approach above, which is why it is recommended.

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.
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.

molin:lead-collected

Fired when the AI successfully collects a lead (the visitor’s name and contact details) in the chat. Use this to fire your own conversion pixels (e.g. Meta Pixel, TikTok Pixel) on real Molin conversions.

Full example