Skip to main content
Required ACL: search 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.
Starting from v2.4.0, you an also pass credentials as headers for each call. If you’re using the client with InstantSearch or Autocomplete, credentials are inferred from the search client.
Use the init method to set global options for the Insights client, for example, set the userToken parameter to send it with every event. To update parameters later, use the partial option. For more information about events, see Get started with events. If the user is signed in, set the authenticated user token, which should come from your system.
JavaScript
import aa from "search-insights";

aa("init", {
  appId: "YourApplicationID",
  apiKey: "YourSearchOnlyAPIKey",
  authenticatedUserToken: "YourUserID",
});
If the user isn’t identified, you can let the Insights API client generate an anonymous user token, and persist it in the cookies.
JavaScript
import aa from "search-insights";

aa("init", {
  appId: "YourApplicationID",
  apiKey: "YourSearchOnlyAPIKey",
  useCookie: true,
});
To set the authenticated user token later, use setAuthenticatedUserToken.

Parameters

apiKey
string
Search API key of your Algolia application.
appId
string
Identifier of your Algolia application.
authenticatedUserToken
string
Pseudonymous identifier for authenticated users.
Don’t include personally identifiable information in user tokens.
See also: User token
Cookie duration in milliseconds. The default is 6 months.For Personalization, at least 3 months (7,776,000,000Β ms) are recommended.
host
string
URL of your server for routing requests before forwarding them to Algolia.
partial
boolean
Whether to partially update the configuration while preserving existing options. Use this to update the settings of a running client without having to specify all options again.
region
enum<string>
Analytics region, one of:
  • de
  • us
Whether to store the anonymous user token in a browser cookie.In some jurisdictions, you need to obtain user consent before using cookies. Make sure to obtain it before you set this option to true. Storing cookies on a user’s device may require consent.Set this parameter to true when using Personalization. See also: Persistent user token
userHasOptedOut
boolean
default:false
Whether to exclude users who opted out from analytics.Set this parameter to true when users request to not be tracked.
userToken
string
Anonymous user identifier.See also: User token
⌘I