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

Set authenticated user token

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 authenticated user token for all subsequent events sent to the Algolia Insights API.

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

Examples

Read the Algolia CLI documentation for more information.

The following example initializes the Insights API client aa. If the user isn’t identified initially, you can let the Insights API client generate an anonymous user token, and persist it in the cookies with the useCookie option.

1
2
3
4
5
6
7
import aa from "search-insights";

aa('init', {
  appId: 'YourApplicationID',
  apiKey: 'YourSearchOnlyAPIKey',
  useCookie: true,
});

When the user logs in, set the authenticated user token to the user ID coming from your system.

1
aa('setAuthenticatedUserToken', 'YourUserID');

Now, both the anonymous and authenticated token will be sent with each event to ensure that data collected when the user was not authenticated is not lost.

When the user logs out, you can unset the authenticated token by passing undefined.

1
aa('setAuthenticatedUserToken', undefined);

Parameters

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

Pseudonymous identifier for authenticated users.

Never include personally identifiable information in user tokens.

See also: User Token

Response

This method doesn't return a response.

Did you find this page helpful?