If you build your own search user interface using the AddSearch Search API, the following data is sent to AddSearch Analytics backend automatically:

  • Keywords used
  • Keywords not returning any results

AddSearch JS client library provides a method to send search result clicks to analytics. Include the JS client library to your search results page’s HTML template:

<script src="https://cdn.jsdelivr.net/npm/addsearch-js-client/dist/addsearch-js-client.min.js"></script>

After you have added the script element, call the following JavaScript function to send clicks to the AddSearch Analytics Dashboard:

var client = new AddSearchClient('YOUR PUBLIC SITEKEY');
client.sendStatsEvent('click', keyword, {documentId: id, position: n});

sendStatsEvent function’s parameters are:

  • keyword: Keyword used to get search results
  • documentId: ID of the search result clicked (32-character long)
  • position: Position of the result being clicked. The first result is 1, the second is 2 and so on.

Recommended event listeners in result links, that fire the sendStatsEvent function, are:

  • onpointerdown: mouse button is clicked or a touch event occurs on mobile
  • onkeyup: Enter is pressed when the link is active

For further documentation, see AddSearch API Client on Github.

The recommended way to create Search UIs is the AddSearch Search UI library which handles analytics events automatically.

Self-learning algorithm

When clicks are sent to analytics, the data is used to improve your search results by our self-learning algorithm.

Was this helpful?

Need more help?

We’re always happy to help with code or other questions you might have. Search our documentation, contact support, or connect with our sales team.