Skip to content

Events

For developers. The widget talks to your page through DOM events on document. Searches and result clicks are counted on their own; you connect two things: the cart button and your order confirmation page. On WooCommerce, the plugin connects both for you.

EventDirectiondetailWhen
typemo:add-to-cartWidget → your pageThe productA visitor pressed a cart button in the results or in an AI Assistant answer. Cancelable
typemo:add-to-cart-successYour page → widget{ id }Your store confirmed the add. The button shows Added
typemo:add-to-cart-errorYour page → widget{ id, message? }The add failed. The button returns to normal

Dispatch the two answers on document, after your server confirms the cart changed. The AI Assistant’s own events are on Your own Ask AI button.

document.addEventListener('typemo:add-to-cart', async (e) => {
const { id, isGrouped } = e.detail;
// A product in variants: let the widget open its page so the shopper picks one.
if (isGrouped) return;
e.preventDefault();
try {
await fetch('/cart/add', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ productId: id, quantity: 1 })
});
document.dispatchEvent(new CustomEvent('typemo:add-to-cart-success', { detail: { id } }));
} catch (err) {
document.dispatchEvent(
new CustomEvent('typemo:add-to-cart-error', { detail: { id, message: err.message } })
);
}
});

Update the cart in place: swap your basket markup, open your cart drawer or bump the counter. Most carts return what you need in their add-to-cart response.

FieldTypeWhat it holds
idstringThe document ID, as in your data
titlestringThe product’s title
urlstringThe product page, or an empty string
pricenumber or undefinedWhat the shopper pays: the sale price when it is lower
imagestring or undefinedThe image URL
collectionIdstringThe collection the product came from
isGroupedbooleantrue when the card stands for several variants
variantCountnumberHow many variants the card stands for
CaseWhat the widget does
Not cancelled, product in variantsOpens the product page in a new tab
Not cancelled, single productNothing more: your listener adds it
Cancelled with preventDefault()Nothing more
No answer event within 2.5 secondsThe button returns to normal
A card already showing AddedIgnores further presses
Your store reloads the page within 10 secondsThe search stays closed after the reload, so the shopper sees the cart; reopening it brings the results back

The widget remembers, in the visitor’s browser, each product they clicked in the results or added to the cart through it. It keeps them for 48 hours, per collection. On your order confirmation page, which must carry the install snippet too, report the ordered items it remembers:

const collectionId = 'products'; // your products collection's ID
function reportPurchase(attempt = 0) {
const widget = window.typemoInstance; // exists once the widget's script has loaded
if (!widget) {
if (attempt < 20) setTimeout(() => reportPurchase(attempt + 1), 100);
return;
}
const attributed = widget.getAttributedDocIds(collectionId);
for (const item of order.items) {
if (attributed.includes(String(item.id))) {
widget.trackPurchase(collectionId, String(item.id), item.total, order.currency);
}
}
widget.clearAttribution(collectionId); // the next order starts fresh
}
reportPurchase();

Each purchase links back to the click and the search that led to it. The numbers land in the Conversions and Revenue cards on Home: see Analytics overview. Embed options lists these methods with trackAddToCart, for a cart add made outside the widget.

Next: Embed options, or Analytics overview to read the results.