Skip to main content
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

searchTerm
string
required
The search query term that generated these results
parameters
object
required
Additional parameters for the tracking event
networkParameters
object
Optional parameters for the network request

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

Item Object Format

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:
  1. trackSearchSubmit - When search is submitted
  2. trackSearchResultsLoaded - When results are displayed (this method)
  3. trackSearchResultClick - When user clicks a result

API Endpoint

This method sends a POST request to:
/v2/behavioral_action/search_result_load

Build docs developers (and LLMs) love