Extract the SearchUid

To record user interactions within a Coveo-powered search results page, products listing page, or recommendations panel, the events you send must include the unique search identifier searchUid of the query that generated the Coveo-powered page.

The main reason for connecting the searchUid of the results with the actions taken on said results, is to measure attribution.

Based on the method you use to build your interface, you can extract the searchUid in the following ways:

Extract the SearchUid with the JavaScript Search Framework

If your listing page is powered by the Coveo JavaScript Search Framework, use the getlastResults method on the QueryController instance to retrieve the searchUid:

const root = document.getElementById(<MY_SEARCH_INTERFACE_ID>);
const queryController =  Coveo.get(root, Coveo.SearchInterface).queryController;
const searchUid = queryController.getLastResults().searchUid;

Extract the SearchUid with Headless

If your listing page is powered by the Coveo Headless library you can retrieve the searchUid from the state of the Headless engine, as follows:

const searchUid = engine.state.search.response.searchUid

Where engine is your Headless engine instance.

Extract the SearchUid with the Rest APIs

If you’re developing directly against the search API, you will find the searchUid in the JSON query response body:

{
  "totalCount" : 10,
  "totalCountFiltered" : 10,
  "duration" : 92,
  "indexDuration" : 23,
  "requestDuration" : 42,
  "searchUid" : "dda6ff39-eeed-436e-88cf-7bc77a36418e",
  ...
}
Recommended Articles