Send events for Recommend analytics
On this page
Recommend Analytics is a beta feature according to the Algolia 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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 a userToken
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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.
-
Install and initialize the search-insights library.
Copy1 2 3 4 5 6
import aa from 'search-insights'; aa("init", { appId: "YourApplicationID", apiKey: "YourSearchOnlyAPIKey", });
-
Copy
1 2 3 4 5 6 7 8 9
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.
1
2
3
4
5
6
window.aa("convertedObjectIDsAfterSearch", {
eventName: "Item Purchased",
index: "YourIndexName",
queryID: "YourQueryID",
objectIDs: ["objectID-1"],
});
Further reading
- For code examples and more information, see Track conversion events.
- If you use Recommend with InstantSearch, see Send events (with InstantSearch).
- If you use an API client, see Send events (with an API client).