Displaying Typeahead Suggestions on Your Agency's Website
Note: this information is for customers who wish to display typeahead (autocomplete) suggestions on their agency’s website. If you are only looking to turn on typeahead suggestions on your search results page, please review the instructions on our Display Overview page.
There are two ways to get typeahead suggestions to appear on your agency’s website.
JavaScript Snippet
We offer a JavaScript snippet that is placed on your pages before the closing </body>
tag.
You must be a Search.gov customer to use this feature. Full instructions and code can be found under Admin Center > YourSite > Activate Search > Code Snippets.
The code will look similar to:
<script type="text/javascript">
//<![CDATA[
var usasearch_config = { siteHandle:"YourSiteHandle" };
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "//search.usa.gov/javascripts/remote.loader.js";
document.getElementsByTagName("head")[0].appendChild(script);
//]]>
</script>
Typeahead API
The typeahead API exposes your site’s typeahead suggestions. Calling the API directly alllows you to show typeahead suggestions without adding the JavaScript code.
This API is available for use on official government websites only. Instructions can be found on the API’s GSA Open API directory listing.
Troubleshooting: Suggestions are derived from the searches performed on your website. For additional details, please review the documentation.