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
The search query term that generated the results
Additional parameters for the tracking event Name of the clicked product item
Unique identifier of the clicked product item
Variation identifier if the item has variants (e.g., size, color)
Search result identifier returned from Constructor.io search response
Whether the item is available for conversion/purchase
Index section name (e.g., “Products”)
Additional analytics data as key-value pairs
Campaign ID if this is a sponsored listing
Campaign owner if this is a sponsored listing
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 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 ,
}
);
});
});
// 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:
trackSearchSubmit - When search is submitted
trackSearchResultsLoaded - When results are displayed
trackSearchResultClick - When user clicks a result (this method)
trackConversion - If the click leads to a conversion
API Endpoint
This method sends a GET request to:
/autocomplete/{term}/click_through