Skip to main content
Sends a search result click event to Constructor.io’s API. This tracks when a user clicks on a product that appeared in search results, which is crucial for understanding search effectiveness.

Method Signature

constructorio.tracker.trackSearchResultClick(term, parameters, networkParameters?)

Parameters

term
string
required
The search query term that generated the 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 result click
constructorio.tracker.trackSearchResultClick(
  'T-Shirt',
  {
    itemName: 'Red T-Shirt',
    itemId: 'KMH876',
  }
);

Complete Example

// Track search result click with all parameters
constructorio.tracker.trackSearchResultClick(
  'T-Shirt',
  {
    itemName: 'Red T-Shirt',
    itemId: 'KMH876',
    variationId: 'KMH876-RED-L',
    resultId: '019927c2-f955-4020-8b8d-6b21b93cb5a2',
    itemIsConvertible: true,
    section: 'Products',
    slCampaignId: 'Campaign 123',
    slCampaignOwner: 'Store 123',
  }
);

Integration Example

// Track when user clicks on a search result
const searchResults = document.querySelectorAll('.search-result');
const searchTerm = new URLSearchParams(window.location.search).get('q');
const resultId = window.searchResultId; // From search API response

searchResults.forEach(result => {
  result.addEventListener('click', () => {
    const itemId = result.dataset.itemId;
    const itemName = result.dataset.itemName;
    const variationId = result.dataset.variationId;
    
    constructorio.tracker.trackSearchResultClick(
      searchTerm,
      {
        itemName: itemName,
        itemId: itemId,
        variationId: variationId,
        resultId: resultId,
      }
    );
  });
});

Example with Analytics Tags

// Track click with custom analytics data
constructorio.tracker.trackSearchResultClick(
  'running shoes',
  {
    itemName: 'Ultra Runner Pro',
    itemId: 'SHOE-001',
    resultId: '019927c2-f955-4020-8b8d-6b21b93cb5a2',
    analyticsTags: {
      position: 3,
      device: 'mobile',
      campaign: 'spring-sale',
    },
  }
);

When to Use

Call trackSearchResultClick() when:
  • A user clicks on a product in search results
  • A user navigates to a product detail page from search
  • A user clicks a quick-view button on a search result

Important Notes

  • Always include the resultId from Constructor.io’s search response for proper attribution
  • The term parameter should match the original search query
  • Track this before navigating away from the search results page
  • Both itemName and itemId are required
  • If the product has variants, include the variationId
If the clicked item is a sponsored listing, include the campaign information:
constructorio.tracker.trackSearchResultClick(
  'coffee',
  {
    itemName: 'Premium Coffee Beans',
    itemId: 'COFFEE-001',
    resultId: '019927c2-f955-4020-8b8d-6b21b93cb5a2',
    slCampaignId: 'fall-campaign-2024',
    slCampaignOwner: 'Brand-X',
  }
);

Relationship with Other Events

Track these events in sequence:
  1. trackSearchSubmit - When search is submitted
  2. trackSearchResultsLoaded - When results are displayed
  3. trackSearchResultClick - When user clicks a result (this method)
  4. trackConversion - If the click leads to a conversion

API Endpoint

This method sends a GET request to:
/autocomplete/{term}/click_through

Build docs developers (and LLMs) love