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.
Cart events
Section titled “Cart events”| Event | Direction | detail | When |
|---|---|---|---|
typemo:add-to-cart | Widget → your page | The product | A visitor pressed a cart button in the results or in an AI Assistant answer. Cancelable |
typemo:add-to-cart-success | Your page → widget | { id } | Your store confirmed the add. The button shows Added |
typemo:add-to-cart-error | Your 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.
The product
Section titled “The product”| Field | Type | What it holds |
|---|---|---|
id | string | The document ID, as in your data |
title | string | The product’s title |
url | string | The product page, or an empty string |
price | number or undefined | What the shopper pays: the sale price when it is lower |
image | string or undefined | The image URL |
collectionId | string | The collection the product came from |
isGrouped | boolean | true when the card stands for several variants |
variantCount | number | How many variants the card stands for |
What happens after a press
Section titled “What happens after a press”| Case | What the widget does |
|---|---|
| Not cancelled, product in variants | Opens the product page in a new tab |
| Not cancelled, single product | Nothing more: your listener adds it |
Cancelled with preventDefault() | Nothing more |
| No answer event within 2.5 seconds | The button returns to normal |
| A card already showing Added | Ignores further presses |
| Your store reloads the page within 10 seconds | The search stays closed after the reload, so the shopper sees the cart; reopening it brings the results back |
Report purchases
Section titled “Report purchases”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.