Events
Searches tell Shoof AI what visitors looked for. Events tell it what they did next. They power:
- analytics: click-through rate, the most clicked results, and revenue from search;
- click-learned ranking: results visitors pick for a query rise for that query;
- trending items and searches;
- bought together.
The widget and the WordPress plugin send events for you. Read on if you built your own search UI.
Event types
Section titled “Event types”| 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. |
Send events
Section titled “Send events”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");curl -s "https://api.shoofai.co/v1/apps/$SHOOF_APP/events" \ -H "x-shoof-api-key: $SHOOF_SEARCH_KEY" -H "content-type: application/json" \ -d '{ "events": [ { "type": "click", "queryId": "xU3s9fQk1", "objectId": "sku-1042-en", "position": 2, "userToken": "anon-4b1d" }, { "type": "conversion", "queryId": "xU3s9fQk1", "objectId": "sku-1042-en", "value": 140, "currency": "AED", "orderId": "10521", "userToken": "anon-4b1d" } ] }'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.
Carry the queryId to the purchase
Section titled “Carry the queryId to the purchase”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.
User tokens
Section titled “User tokens”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
localStorageor 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.
Searches your visitors didn’t type
Section titled “Searches your visitors didn’t type”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).
Retention
Section titled “Retention”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.