Skip to main content
Search insights is Algolia’s JavaScript library for tracking user interactions, such as clicks, conversions, and views, and sending them to the Insights API. It’s designed to run in the browser and integrates seamlessly with Algolia’s search and discovery libraries, including InstantSearch and Autocomplete. To learn more, see:

Install the Search Insights library

To send events from your JavaScript app, either include a code snippet directly in your HTML or install it as a dependency to your project.

Include the Search Insights library in your HTML

Add the following code snippet to the head tag of every page where you want to track events:
HTML
<script>
  var ALGOLIA_INSIGHTS_SRC = "https://cdn.jsdelivr.net/npm/search-insights@2.17.3/dist/search-insights.min.js";

  !function(e,a,t,n,s,i,c){e.AlgoliaAnalyticsObject=s,e[s]=e[s]||function(){
  (e[s].queue=e[s].queue||[]).push(arguments)},e[s].version=(n.match(/@([^\/]+)\/?/) || [])[1],i=a.createElement(t),c=a.getElementsByTagName(t)[0],
  i.async=1,i.src=n,c.parentNode.insertBefore(i,c)
  }(window,document,"script",ALGOLIA_INSIGHTS_SRC,"aa");
</script>
If you prefer hosting your own version, copy the script into your own project.
HTML
<script>
  var ALGOLIA_INSIGHTS_SRC = 'path/to/search-insights.min.js';

  // ...
</script>

Install the Serch Insights library as npm package

Add the search-insights package as a dependency to your project:
npm install search-insights
You can find the source code on GitHub. To initialize the Insights client in your app, see init.
I