Sends an autocomplete select event to Constructor.io’s API. This tracks when a user clicks or navigates to a result within autocomplete/autosuggest dropdown.
Method Signature
constructorio . tracker . trackAutocompleteSelect ( term , parameters , networkParameters ? )
Parameters
The term or name of the selected autocomplete item
Additional parameters for the tracking event The current autocomplete search query that the user had typed
The section name where the selected item resides (e.g., “Products”, “Search Suggestions”)
Trigger used to select the item (e.g., “click”, “enter”)
Group identifier if searching within a group (e.g., “Pumpkin in Canned Goods”)
Display name of the group
Product item unique identifier (for product selections)
Campaign ID of sponsored listing
Campaign owner of 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 autocomplete selection
constructorio . tracker . trackAutocompleteSelect (
'T-Shirt' ,
{
originalQuery: 'Shirt' ,
section: 'Products' ,
}
);
Complete Example
// Track autocomplete selection with all parameters
constructorio . tracker . trackAutocompleteSelect (
'T-Shirt' ,
{
originalQuery: 'Shirt' ,
section: 'Products' ,
tr: 'click' ,
groupId: '88JU230' ,
displayName: 'apparel' ,
itemId: '12345' ,
slCampaignId: 'Campaign 123' ,
slCampaignOwner: 'Store 123' ,
}
);
Integration Example
// Track when user clicks autocomplete result
const autocompleteResults = document . querySelectorAll ( '.autocomplete-result' );
autocompleteResults . forEach ( result => {
result . addEventListener ( 'click' , ( e ) => {
const term = e . target . dataset . term ;
const itemId = e . target . dataset . itemId ;
const searchQuery = document . querySelector ( '#search-input' ). value ;
constructorio . tracker . trackAutocompleteSelect (
term ,
{
originalQuery: searchQuery ,
section: 'Products' ,
tr: 'click' ,
itemId: itemId ,
}
);
});
});
When to Use
Call trackAutocompleteSelect() when:
A user clicks on an autocomplete suggestion
A user navigates to a suggestion via keyboard and presses Enter
A user selects any item from the autocomplete dropdown
Important Notes
The term parameter should be the selected item’s name, not the original query
The originalQuery parameter should be what the user typed in the search box
Always include the section to properly categorize the selection
Track both product selections and search suggestion selections
API Endpoint
This method sends a GET request to:
/autocomplete/{term}/select