Insights
Init |
Initialize the Insights API client to communicate with the Algolia Insights API. |
Clicked object IDs after search |
Send a click event related to an Algolia request. |
Clicked object IDs |
Send a click event to capture clicked items. |
Clicked filters |
Send a click event to capture when users select filters. |
Converted object IDs after search |
Send a conversion event related to an Algolia request. |
Converted object IDs |
Send a conversion event to capture clicked items. |
Converted filters |
Send a conversion event to capture the filters a user selected when converting. |
Added to cart object IDs after search |
Send a conversion event related to an Algolia request to capture when users add items to their shopping cart. |
Added to cart object IDs |
Send a conversion event to capture when users add items to their shopping cart. |
Purchased object IDs after search |
Send a conversion event related to an Algolia request to capture when users purchase items. |
Purchased object IDs |
Send a conversion event to capture when users purchase items. |
Viewed object IDs |
Send a view event to capture viewed items. |
Viewed filters |
Send a view event to capture the active filters for items a user viewed. |
Send events |
Send a list of events in a single request. |
Set user token |
Set the anonymous user token for all subsequent events sent to the Algolia Insights API. |
Get user token |
Get the anonymous user token from the Insights API Client state. |
Set authenticated user token |
Set the authenticated user token for all subsequent events sent to the Algolia Insights API. |
Get authenticated user token |
Get the authenticated user token from the Insights API Client state. |
Add user agent |
Add a custom user agent to the request. |
We released a new version of the PHP API client in public beta. Read the beta documentation for more information.
We released a new version of the Java API client in public beta. Read the beta documentation for more information.
The Algolia Insights API lets you collect events related to your search and discovery experience. Events are actions that users take on your app or website. They unlock powerful features, such as recommendations, personalization, smarter search results, and analytics that help you optimize your user experience.
Install the Insights client
The Insights client is a separate npm package. Find the source code on GitHub.
To send Insights events from your JavaScript app, either include a code snippet directly in your HTML or install it as a dependency in your project.
Include the Insights client in your HTML
Paste the following code snippet into the <head>
tag of every page where you want to track Insights events.
1
2
3
4
5
6
7
8
<script>
var ALGOLIA_INSIGHTS_SRC = "https://cdn.jsdelivr.net/npm/search-insights@2.13.0/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 in your own project.
1
2
3
4
5
<script>
var ALGOLIA_INSIGHTS_SRC = 'path/to/search-insights.min.js';
// …
</script>
Install the Insights client with npm
Install the search-insights
package in your project:
1
2
3
npm install search-insights
# or
yarn add search-insights
Initialize the Insights client
To initialize the Insights client, you need your Algolia application ID and your API key with search
permissions.
You can find both in your Algolia dashboard.
1
2
3
4
5
6
7
8
<?php
require_once __DIR__."/vendor/autoload.php";
use Algolia\AlgoliaSearch\InsightsClient;
$insightsClient = InsightsClient::create(
"YourApplicationID",
"YourSearchOnlyAPIKey"
)
Find all the parameters you can use in the init
method documentation.
Starting from v2.4.0, you can also pass credentials using headers
for each call. If you’re using the client with InstantSearch or Autocomplete, credentials are inferred from the passed search client.
Identify users
It’s important to identify users so that you can give them a consistent experience, especially when using Personalization. Do this by providing an anonymous or pseudonymous user identifier (a userToken
or authenticatedUserToken
) when tracking Insights events.