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.

About this method # A

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 # A

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: 'AJ0P3S7DWQ',
  apiKey: '90dfaaf5755e694f341fe68f6e41a6d4',
  useCookie: true,
});

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

1
2
3
4
5
aa('init', {
  appId: 'AJ0P3S7DWQ',
  apiKey: '90dfaaf5755e694f341fe68f6e41a6d4',
  userToken: 'AnonymousID',
});

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

Parameters # A

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

Anonymous user identifier.

See also: User Token

Response # A

This method doesn't return a response.

Did you find this page helpful?
PHP v3