Skip to main content
This is a beta feature according to Algolia’s Terms of Service (“Beta Services”).
Events are actions that users take on your app or website. They unlock powerful analytics that help you optimize your user experience. With the Insights API, you can capture all important events related to your search and discovery experience. If you are familiar with Search analytics, you will find that many of the concepts and metrics are similar, but if this is the first time you are sending events to Algolia, see Get started with events.

Start your implementation

The best way to send events to Algolia depends on where you’re sending them from. Algolia provides tools to help you make sure your events have all the necessary details.

Client-side versus server-side events

It’s best to send events straight from your users’ devices. To do this, see Send events from your frontend. If you’re not collecting enough events compared to the number of visitors to your website or app, it might be because your users use ad blockers. In this case, consider server-side tracking.

Get started with Algolia Recommend analytics

Algolia Recommend Analytics is built on the same foundational concepts as Search Analytics and should feel familiar if you’ve used it before.

Enable events collection

Set the clickAnalytics parameter to true when making Recommend requests. This includes the queryID parameter in the Recommend response, which is required for linking events and recommendations.
JavaScript
const response = await client.getRecommendations({
  requests: [
    {
      // All models except `trending-facets` are supported.
      model: "related-products",
      indexName: "indexName",
      objectID: "objectID",
      threshold: 0,
      queryParameters: {
        clickAnalytics: true, 
      },
    },
  ],
});

// Use this queryID when sending click and conversion events
const queryID = response.results[0].queryID;
For more information, see What is a query id and Keep track of query IDs.

Send user tokens

User tokens are strings that uniquely identify users throughout your app. They link click and conversion events with user profiles. For more information, see User token.
JavaScript
const response = await client.getRecommendations({
  requests: [
    {
      model: "related-products",
      indexName: "indexName",
      objectID: "objectID",
      threshold: 0,
      queryParameters: {
        clickAnalytics: true,
        userToken: "user-1234", 
      },
    },
  ],
});
These parameters should be passed to the Recommend request. For more information, see Get recommendations.

Send click and conversion events

To get the most out of your Recommend analytics, start collecting click and conversion events with the Algolia Insights API. Recommend analytics relies on the same Insights API as Search analytics. You can use the same methods to send events.
  1. Install and initialize the search-insights library.
    JavaScript
    import aa from "search-insights";
    
    aa("init", {
      appId: "ALGOLIA_APPLICATION_ID",
      apiKey: "ALGOLIA_SEARCH_API_KEY",
    });
    
  2. Track click events.
    JavaScript
    window.aa("clickedObjectIDsAfterSearch", {
      index: "YourIndexName",
      eventName: "Item Clicked",
      // Fields from the Recommend response.
      queryID: "YourQueryID",
      objectIDs: ["objectID-1"],
      positions: [1],
    });
    
You can also track conversion events.
JavaScript
window.aa("convertedObjectIDsAfterSearch", {
  eventName: "Item Purchased",
  index: "YourIndexName",
  queryID: "YourQueryID",
  objectIDs: ["objectID-1"],
});

See also

I