Skip to main content

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:
FieldTypeDescription
search_locationstringEither "quick" (header autocomplete) or "page".
search_termstringThe text the user searched for.
no_of_resultsnumberTotal number of search results (searchResponse.Data.total_count).
skuarray of stringsFlat array of all result SKUs.
search_sourcestringFor suggestion clicks, pass the autocomplete category key from the response (e.g., "popular_search", "recent_search").
used_suggestionstringThe exact suggestion text the user clicked (e.g., “shirts”, “jeans”).
facetsarray of objectsActive filters, each { field: <string>, value: <string> }.
request_idstringUnique identifier for the search request (x-request-id from response headers).
page_depthstringCurrent 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:
// 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
});