Responding to Events

/*
* The client has received and is displaying results.
*/
search.on("received.results", function (response) {
var request = search.getRequestFromUrl(window.location.href);
ga(
"send",
"event",
"search results",
"loaded",
request.term,
response.total_num_results
);
});
/*
* The user has clicked on a search result. If this event has no handlers,
* the client will automatically send users to the URL of the associated result.
*/
search.on("clicked.result", function (event, info) {
window.location = info.result.data.url;
});
/*
* The user has clicked on a section result. If this event has no handlers,
* the client will automatically send users to the URL of the associated result.
*/
search.on("clicked.sectionResult", function (event, info) {
window.location = result.data.url;
});
/*
* The user has requested a new page of search results by clicking on a UI
* component such as a facet, a group, or a pager. Every custom search client
* has a getUrlFromRequest() function that is specific to the customer
* website and translates a search request object into a search URL. If this
* event has no handlers, the client will automatically send users to a new page.
*/
search.on("update.request", function (request) {
var url = search.getUrlFromRequest(request);
window.location = url;
});
/*
* The user has searched for a term that returns a redirect. If this event has
* no handlers, the client will automatically send users to the URL of the
* associated redirect and remove the current URL from history
*/
search.on("redirected", function (redirect) {
window.location.replace(redirect.data.url);
});

When a user interacts with the search client or when Constructor.io services communicate with the search client, the client emits its own events that the page can handle. Here are a list of the events available and the data that they send.

Note that all events are optional, but that for some events if there are no handlers the search client will handle the event in a sensible manner.