🎉 Try the public beta of the new docs site at algolia.com/doc-beta! 🎉
API client / Methods / Insights

This method is only available for JavaScript.

Required API Key: any key with the search ACL
Method signature
Only available for JavaScript

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.

You’re currently reading the Ruby API client v2 documentation. Check the migration guide to learn how to upgrade from v1 to v2. You can still access the v1 documentation.

About this method

Set the anonymous user token for all subsequent events sent to the Algolia Insights API.

Use this method to automatically send the userToken with every event.

Examples

Read the Algolia CLI documentation for more information.

For more information about initializing the Insights client aa, see Initialize the Insights client.

1
aa('setUserToken', 'AnonymousID');

You can let the Insights API client generate an anonymous user token for you and store it in a cookie on the user’s device. For more information, see the useCookie option.

1
2
3
4
5
aa('init', {
  appId: 'YourApplicationID',
  apiKey: 'YourSearchOnlyAPIKey',
  useCookie: true,
});

Alternatively, you can provide your own anonymous user token on init.

1
2
3
4
5
aa('init', {
  appId: 'YourApplicationID',
  apiKey: 'YourSearchOnlyAPIKey',
  userToken: 'AnonymousID',
});

When the user logs in, synchronize the user token with the user ID coming from your system with setAuthenticatedUserToken.

Parameters

Parameter Description
userToken
type: string
pattern: [A-Za-z0-9_=+/-]{1,129}

Anonymous user identifier.

See also: User Token

Response

This method doesn't return a response.

Did you find this page helpful?