Set authenticated user token
This method is only available for JavaScript.
search
ACL
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 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 tokens will be sent with each event to ensure that data collected when users weren’t authenticated isn’t lost.
When users log 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.