> ## Documentation Index
> Fetch the complete documentation index at: https://help.experro.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Products Searched

## Products Searched (`product_searched`)

**Purpose:**
Track whenever a user performs a search either from the header search bar or the on‑page search interface.

**When to Fire:**
After you receive the search API response, immediately log how many results were returned along with contextual details (search term, location, filters, etc.).

**Payload Schema:**

| Field             | Type             | Description                                                                                                                |
| ----------------- | ---------------- | -------------------------------------------------------------------------------------------------------------------------- |
| `search_location` | string           | Either `"quick"` (header autocomplete) or `"page"`.                                                                        |
| `search_term`     | string           | The text the user searched for.                                                                                            |
| `no_of_results`   | number           | Total number of search results (`searchResponse.Data.total_count`).                                                        |
| `sku`             | array of strings | Flat array of all result SKUs.                                                                                             |
| `search_source`   | string           | For suggestion clicks, pass the autocomplete category key from the response (e.g., `"popular_search"`, `"recent_search"`). |
| `used_suggestion` | string           | The exact suggestion text the user clicked (e.g., "shirts", "jeans").                                                      |
| `facets`          | array of objects | Active filters, each `{ field: <string>, value: <string> }`.                                                               |
| `request_id`      | string           | Unique identifier for the search request (x-request-id from response headers).                                             |
| `page_depth`      | string           | Current page number (1, 2, 3, etc.).                                                                                       |

#### Clarification: autocomplete suggestions

* `search_source`: set this to the suggestion category key returned by your autocomplete API for the clicked item (e.g., `"popular_search"`, `"recent_search"`, `"category"`, `"search_suggestion"`, etc.).
* `used_suggestion`: set this to the exact suggestion text the user clicked (e.g., `"shirts"`, `"jeans"`).

**Example:**

```js theme={null}
// Assume these variables are populated from your search response and UI state:
const totalCount       = searchResponse.Data.total_count;
const searchTerm       = 'running shoes';
const searchLocation   = 'page'; // or 'quick'
const products         = searchResponse.Data.records;
const selectedFacets   = [{ field: 'size', value: '10' }, { field: 'brand', value: 'BrandX' }];
const requestId        = searchResponse.headers.get('x-request-id');
const currentPage      = 1; // Current page number (1, 2, 3, etc.)

ExpAnalyticsService.trackProductSearched({
  search_location: searchLocation,
  search_term: searchTerm,
  no_of_results: totalCount,
  sku: products.map(item => item.sku),
  search_source: searchSource,
  used_suggestion: usedSuggestion,
  facets: selectedFacets,
  request_id: requestId,
  page_depth: currentPage
});
```
