--- title: Extract the searchUid slug: l2jb0279 canonical_url: https://docs.coveo.com/en/l2jb0279/ collection: coveo-for-commerce source_format: adoc --- # Extract the searchUid > **Important** > > We strongly recommend that all new Commerce implementations use the [Event Protocol](https://docs.coveo.com/en/o1n91230/) to log events. 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`](https://coveo.github.io/search-ui/interfaces/iqueryresults.html#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](https://docs.coveo.com/en/m7l98577/). 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](https://docs.coveo.com/en/187/), use the [`getlastResults`](https://coveo.github.io/search-ui/classes/querycontroller.html#getlastresults) method on the `QueryController` instance to retrieve the `searchUid`: ```js const root = document.getElementById(); 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](https://docs.coveo.com/en/headless/latest/) you can retrieve the `searchUid` from the state of the Headless engine, as follows: ```typescript 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](https://docs.coveo.com/en/13#operation/searchUsingGet), you'll find the `searchUid` in the JSON query response body: ```js { "totalCount" : 10, "totalCountFiltered" : 10, "duration" : 92, "indexDuration" : 23, "requestDuration" : 42, "searchUid" : "dda6ff39-eeed-436e-88cf-7bc77a36418e", ... } ```