Skip to content

Events

Searches tell Shoof AI what visitors looked for. Events tell it what they did next. They power:

The widget and the WordPress plugin send events for you. Read on if you built your own search UI.

Type Send when With
click A visitor opens a result. queryId, objectId, position
view A visitor opens an item’s page, from search or anywhere else. objectId
add_to_cart A visitor adds an item to their cart. objectId, and the queryId that led to it
conversion A visitor buys an item. One event per item in the order. objectId, queryId, value, currency, orderId
Field Notes
type Required.
objectId The record’s id.
queryId The queryId of the search that led to this. Without it, an event still counts for trending and bought-together, but not for search analytics or learned ranking.
position The result’s 1-based position on the page, for clicks.
userToken The visitor’s anonymous ID. See user tokens.
value, currency The amount of a conversion, such as 140 and AED.
orderId Groups the items of one order, for bought-together.
timestamp Epoch milliseconds. Defaults to when the event arrives.

POST /events takes up to 100 events and answers 202 Accepted. Send them with the search key, from the browser.

const res = await client.search({ q: "trail shoes" });
// The visitor clicks the 2nd result:
client.clicked(res.queryId, res.hits[1].id, 2);
// Later, they buy it (send one per item in the order):
client.converted(res.queryId, res.hits[1].id, 140, "AED", "order-10521");
// On any product page:
client.viewed("sku-1042-en");

clicked, viewed and converted use navigator.sendBeacon, so the event still arrives when the click navigates away from the page. Beacons can’t set headers, so the client sends the key in the URL (?apiKey=) and the body as text/plain, which the API accepts.

A purchase usually happens pages after the search. Remember which search led to each item when it’s clicked, for example in sessionStorage, and send that queryId with the add-to-cart and the purchase. The widget does this for 30 minutes within a browser session.

A userToken is an anonymous ID you pick for each visitor, up to 128 characters. It lets analytics count visitors rather than requests, and keeps one person’s clicks from looking like a crowd’s.

  • Use the same token for a visitor’s searches and events.
  • Don’t use emails, names or other personal data. A random ID kept in localStorage or a first-party cookie is ideal. The JavaScript client and the widget make one for you (anon-…).
  • A secured key can carry a userToken, which then overrides the one in requests.

Set "analytics": false on searches a visitor didn’t type, such as the search behind a category page or a “you may also like” strip. They then stay out of analytics, and their clicks don’t teach learned ranking. Those with a query still count towards your search quota; a search with no query never counts (what counts).

Events and searches are kept for 90 days, in your app’s region. How much history the dashboard’s analytics show depends on your plan: 30 days on Free, 90 on the paid plans.