> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Search Insights JavaScript library

> Library for reporting click, conversion, and view metrics the Algolia Insights API.

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:

* [Choose how to send events](/doc/guides/sending-events/getting-started)
* [Send events with InstantSearch](/doc/guides/building-search-ui/events/js)
* [Send events with Autocomplete](/doc/ui-libraries/autocomplete/guides/sending-algolia-insights-events)
* [Insights API reference](/doc/rest-api/insights)

## 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 HTML icon=code-xml theme={"system"}
<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 HTML icon=code-xml theme={"system"}
<script>
  var ALGOLIA_INSIGHTS_SRC = 'path/to/search-insights.min.js';

  // ...
</script>
```

### Install the Search Insights library as npm package

Add the `search-insights` package as a dependency to your project:

<CodeGroup>
  ```sh npm theme={"system"}
  npm install search-insights
  ```

  ```sh yarn theme={"system"}
  yarn add search-insights
  ```

  ```sh pnpm theme={"system"}
  pnpm add search-insights
  ```
</CodeGroup>

You can find the source code on [GitHub](https://github.com/algolia/search-insights.js).

To initialize the Insights client in your app,
see [`init`](/doc/libraries/search-insights/init).
