Enable events collection
Set theclickAnalytics
parameter to true
when making search requests.
This includes the queryID
parameter in the search response,
which is required for linking events and search requests.
JavaScript
Initialize search-insights.js
Install thesearch-insights
library.
search-insights
library, initialize the client in your website.
JavaScript
Understand which events to track
To understand which events you should send, think about the different steps a user takes through your website to perform desired actions, such as watching a video, reading an article, or liking a page.- Search results page
- Browse page
- External referrals

- Select content from the search results to open the content details page.
- Consume content, such as watching a video, reading an article, or listening to an audio track.
- Interact with content, such as liking, subscribing, or following.
Search and search results pages
User action | Method name |
---|---|
User clicks search result | clickedObjectIDsAfterSearch |
User clicks categories/filters | clickedFilters |
User views search results | viewedObjectIDs |
Browse/category page
User action | Method name |
---|---|
User clicks content | clickedObjectIDsAfterSearch |
User views content | viewedObjectIDs |
Content details page
User action | Method name |
---|---|
User views content | viewedObjectIDs |
Keep track of query IDs
Conversion events are often triggered outside of the search results page. In order to correctly attribute which query is responsible for a conversion, it is necessary to keep track of the query ID returned when a search is performed so that it can be included in conversion events. To relate the conversion events back to the search request made on your search results or category pages, you need to keep track of the query IDs across your pages.Track click events
Click events capture when users indicate they want to view specific pieces of content. Add the following code to track a user navigating to a piece of content from a search results page:JavaScript
queryID
parameter of the clickedObjectIDsAfterSearch
method is used by Algolia to relate the event to a prior search
or browse event.
The objectIDs
parameter of the clickedObjectIDsAfterSearch
method should contain the ID of the article.
This can be retrieved from the objectID
field of the hits
array returned from the search request.
The positions
parameter of the clickedObjectIDsAfterSearch
method indicates the position of the item in the search results. For example, if the user clicked on the top result on the page, positions should be [1]
.
If a user found a piece of content without performing a search—for example, they
browsed there from elsewhere on your site, add the following code to track that:
JavaScript
Track conversion events
An example of a conversion event that may be relevant to your media site:JavaScript
window.aa
object is the API client for the Insights API and is globally available
if you enabled automatic events collection.
The queryID
parameter of the convertedObjectIDsAfterSearch
method is used by Algolia to relate the event to a prior search.
The objectIDs
parameter of the convertedObjectIDsAfterSearch
method indicates which items were part of the conversion.
The objectID
parameter is included in the search response for each hit.
If the event is not directly related to a search, for example, it’s triggered on the homepage,
use the convertedObjectIDs
method instead.
JavaScript
Article Bookmarked
: a user bookmarked an article.Article Liked
: a user liked an article.Article Recommended
: a user recommended an article.Playlist Followed
: a user followed a playlist.Author Followed
: a user followed an author.Brand Followed
: a user followed a brand.
Track additional click events
For Algolia Recommend and Personalization, capture additional click events when users select individual items:- On your home page
- From recommendations
JavaScript
Optional: handle known users for Personalization
For effective personalization, you need to identify users across sessions. It’s best to use an identifier from your authentication system after users signed in. For more information, see User token. After getting the identifier from your system, set it asauthenticatedUserToken
parameter.
JavaScript
authenticatedUserToken
parameter in the Insights client, you also need to update
the user token you send with your search requests.
JavaScript
JavaScript
Optional: send view events for Personalization
Personalization benefits from the same click and conversion events, plus it can use view events to enrich user profiles. To capture view events, such as when a user views search results, use the following code snippet.JavaScript
You don’t need to send a
queryID
when tracking view events.