clickAnalytics to true, the search response includes the queryID.
Users often reach the conversion page from several searches,
so the page doesn’t know which search produced each item.
Each item may need the query ID of a different search.
To attribute conversions correctly, capture and send the right query ID with each event.
Get a query ID for every search
If you use InstantSearch or Autocomplete, set theinsights option to true:
If you use one of the API clients,
set the clickAnalytics parameter to true:
Automatic query ID inference for conversion events
If a conversion event and an earlier click event share the same user token, , , andobjectID, Algolia automatically infers the queryID.
This happens when Algolia processes events.
You don’t need to configure anything.
This means you might not need to track the query ID manually.
For best accuracy, set the queryID whenever possible with one of the following methods.
Match the query ID requirements of your conversion events
Which query IDs you need to keep, and for how long, depends on the events you send when users convert:convertedObjectIDsAfterSearchaccepts onequeryIDfor the whole event. AllobjectIDsin the event must come from the same search.addedToCartObjectIDsAfterSearchandpurchasedObjectIDsAfterSearchaccept aqueryIDper item in theobjectDataarray. Use this for events with items that originate from different searches, such as a cart checkout. Revenue analytics doesn’t include items without aqueryID.
Track query IDs across pages
Choose one of the following methods to track the query ID from a search until the user converts.Track query IDs as URL parameters
Add thequeryID as a URL parameter to the URL of the destination page.
For example, on your InstantSearch search results page:
queryID from the URL, use the URL API:
JavaScript
queryID, this method works for conversions on the destination page itself.
A shared page, such as a checkout page, can hold items from several searches.
For conversions there, store a query ID for each item with one of the following methods.
When you use URL parameters to track the query ID,
follow SEO best practices.
For more advice, read the article URL parameter handling in the Search Engine Journal.
Automatically track query IDs
If you use InstantSearch or Autocomplete, you don’t need to track query IDs yourself. Both libraries track the query ID when users click search results. If you passinferQueryID: true for each call,
search-insights automatically includes the queryID in the payload of conversion events.
Track query IDs in cookies or local storage
If you can’t use the automatic query ID tracking in InstantSearch or Autocomplete, build a similar pattern yourself. Track the query ID in a cookie,localStorage, or sessionStorage.
When a user clicks a result and a query ID is available, write an entry to a cache of query IDs.
Key each entry by index name and objectID:
JavaScript
queryID so you can cap the size of the cache.
When a write exceeds the cap, discard the oldest entries.
When a user converts, retrieve the cached queryID for that index and objectID.
Include it in the conversion event.
After a successful conversion event, delete that entry from the cache.
If you store the query ID in a cookie or the browser’s local storage, you may need your users’ consent.
Agentic query IDs
Agentic interfaces can show results that an assistant selected, reordered, or explained. Attribute events from these results to the assistant message that showed them, not only to the underlying Search API request. If you use InstantSearch Chat, InstantSearch creates and sends this agenticqueryID automatically for events from assistant-rendered results.
If you integrate with the Agent Studio API yourself, use the assistant message ID from your conversation state.
With Agent Studio, this is the id of the assistant message in the completion response.
Store that assistant message, including its id.
When you send the assistant message back as part of the conversation history, reuse the same ID.
Build the agentic queryID from that assistant message ID:
alg_msg_assistant_002, the queryID is:
- Use the same
queryIDfor all results shown in the same assistant message. - Use the same
queryIDfor clicks and conversions that come from those results. - Don’t create a new
queryIDfor each render, click, or event retry. - Don’t use an agentic
queryIDfor events that aren’t caused by an agent-rendered result.
search-insights library:
JavaScript
1.
Users can open a detail page from an assistant message and convert later.
In that case, pass the agentic queryID like a regular search queryID, such as in the URL:
queryID in the later conversion event.
Track conversions unrelated to a search
To track conversions unrelated to a previous search, send a conversion event without aqueryID.
For more information about where you can use conversion events without a query ID,
see Event types.