Sends a search results loaded event to Constructor.io’s API. This tracks when search results are displayed on a search results page, providing important context about what the user saw.
Method Signature
constructorio . tracker . trackSearchResultsLoaded ( searchTerm , parameters , networkParameters ? )
Parameters
The search query term that generated these results
Additional parameters for the tracking event URL of the search results page
List of product items displayed in search results. Each item should have an itemId property
Total number of results available
Current page number of results (1-indexed)
Search result identifier returned from Constructor.io search response
Currently selected filters as key-value pairs
Sort order: “ascending” or “descending”
Field being sorted by (e.g., “price”, “relevance”)
Index section name (e.g., “Products”)
Additional analytics data as key-value pairs
Optional parameters for the network request Request timeout in milliseconds
Returns
Returns true on success or an Error object if validation fails.
Examples
Basic Example
import ConstructorIOClient from '@constructor-io/constructorio-client-javascript' ;
const constructorio = new ConstructorIOClient ({
apiKey: 'YOUR_API_KEY' ,
});
// Track search results loaded
constructorio . tracker . trackSearchResultsLoaded (
'T-Shirt' ,
{
url: window . location . href ,
items: [
{ itemId: 'KMH876' },
{ itemId: 'KMH140' },
{ itemId: 'KMH437' },
],
resultCount: 167 ,
}
);
Complete Example with Filters and Sorting
// Track search results with all parameters
constructorio . tracker . trackSearchResultsLoaded (
'T-Shirt' ,
{
url: window . location . href ,
items: [
{ itemId: 'KMH876' },
{ itemId: 'KMH140' },
{ itemId: 'KMH437' },
],
resultCount: 167 ,
resultPage: 3 ,
resultId: '019927c2-f955-4020-8b8d-6b21b93cb5a2' ,
selectedFilters: {
brand: [ 'Nike' , 'Adidas' ],
color: [ 'blue' ],
},
sortOrder: 'ascending' ,
sortBy: 'price' ,
section: 'Products' ,
}
);
Integration Example with API Response
// After receiving search results from Constructor.io
async function performSearch ( searchTerm ) {
const response = await constructorio . search . getSearchResults ( searchTerm );
// Extract items from response
const items = response . results . map ( item => ({
itemId: item . data . id ,
}));
// Track that results were loaded
constructorio . tracker . trackSearchResultsLoaded (
searchTerm ,
{
url: window . location . href ,
items: items ,
resultCount: response . total_num_results ,
resultId: response . result_id ,
section: 'Products' ,
}
);
// Display results to user...
}
Example with Item Details
// Items can include additional details
constructorio . tracker . trackSearchResultsLoaded (
'running shoes' ,
{
url: window . location . href ,
items: [
{ itemId: 'SHOE-001' , itemName: 'Ultra Runner' , variationId: 'size-10' },
{ itemId: 'SHOE-002' , itemName: 'Speed Racer' , variationId: 'size-9' },
{ itemId: 'SHOE-003' , itemName: 'Trail Blazer' , variationId: 'size-11' },
],
resultCount: 45 ,
resultId: '019927c2-f955-4020-8b8d-6b21b93cb5a2' ,
}
);
When to Use
Call trackSearchResultsLoaded() when:
Search results are rendered on the page
A user navigates to a search results page
Filters or sorting are applied and results update
Pagination changes and new results load
Important Notes
Always include the resultId from Constructor.io’s search response for proper attribution
The items array can contain up to 100 items (automatically truncated if more)
Items can be simple objects with just itemId or include additional properties
Track this event after results are rendered, not when the request is made
Re-track when filters or sorting changes
Each item in the items array can include:
itemId (required): Unique identifier for the product
itemName (optional): Name of the product
variationId (optional): Variation identifier if applicable
Relationship with Other Events
Track these events in sequence:
trackSearchSubmit - When search is submitted
trackSearchResultsLoaded - When results are displayed (this method)
trackSearchResultClick - When user clicks a result
API Endpoint
This method sends a POST request to:
/v2/behavioral_action/search_result_load