Insights API client methods
This is documentation for v3 of the PHP API clients, which is not the latest version. To see the documentation for the latest version, see PHP v4.
This is documentation for v2 of the Ruby API clients, which is not the latest version. To see the documentation for the latest version, see Ruby v3.
This is documentation for v4 of the JavaScript API clients, which is not the latest version. To see the documentation for the latest version, see JavaScript v5.
This is documentation for v3 of the Python API clients, which is not the latest version. To see the documentation for the latest version, see Python v4.
This is documentation for v8 of the Swift API clients, which is not the latest version. To see the documentation for the latest version, see Swift v9.
This is documentation for v2 of the Kotlin API clients, which is not the latest version. To see the documentation for the latest version, see Kotlin v3.
This is documentation for v6 of the C# API clients, which is not the latest version. To see the documentation for the latest version, see C# v7.
This is documentation for v3 of the Java API clients, which is not the latest version. To see the documentation for the latest version, see Java v4.
This is documentation for v3 of the Go API clients, which is not the latest version. To see the documentation for the latest version, see Go v4.
This is documentation for v1 of the Scala API clients, which is not the latest version. To see the documentation for the latest version, see Scala v2.
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. |
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.17.2/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.