HomeDev GuideAPI Reference
Dev GuideAPI ReferenceUser GuideGitHubNuGetDev CommunityDoc feedbackLog In


Search statistics provide an **HTTP API** for tracking searches and collecting statistical data about them. The aggregated statistics expose functionality you can use to enhance the search: autocomplete, spelling suggestions, and related queries.

Although you can interact with the search statistics API using any programming language that makes HTTP requests, API usage is typically done via JavaScript.

## Track method

To gather search statistics for later analysis, use the `Track()` method in the search query:



See [Tracking](🔗) for more information.

## Autocomplete

After adding some autocomplete text in the Search & Navigation user interface under [Manage > Optimization > Autocomplete](🔗), the autocomplete feature can be enabled on the search textbox in the front-end. Add a jQuery script to add autocomplete, as shown below.

Note

The autocomplete example is dependent upon jQuery and jQuery UI scripts used on your website. However, there are no jQuery requirements for Optimizely Search & Navigation Autocomplete. You can use any library of choice or solution to make this work on your website.

<https://jqueryui.com/> <https://jquery.com/>

Note

Security restrictions may prevent you from using JSONP with Optimizely Search & Navigation’s Autocomplete.



Then, add `txtSearch` to the search form:



Note

Autocomplete only works from the beginning of a phrase. The search term must begin with the first word. You can get existing autocomplete items from the \_autocomplete/list endpoint: /\_autocomplete/list?q=(%40%20%7C"")YOURWORD.\*

## Spellcheck

Based on what other users searched for, search statistics can provide spellchecks, popular queries similar to the one passed to the spellchecker. A jQuery example is below.



The spellchecker accepts these parameters:

  • **query**  – (required) the query to return spellchecks for.

  • **size**  – (optional) the number of spellchecks to return.

## Related queries

Sometimes, it is valuable to discover search relationships, for example people who search for **a** also search for **b**. In search statistics this is called _related queries_. You can request them with the following jQuery.



Related queries accept these parameters:

  • **query**  – (required) the query for which to return related queries.

  • **size**  – (optional) the number of related queries to return.