Skip to main content
Required ACL: search Use this method to automatically send the userToken with every event. For more information, see User token.

Examples

For more information about initializing the JavaScript Insights client aa, see Initialize the Insights client.
JavaScript
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 the useCookie parameter in the init method.
JavaScript
aa("init", {
  appId: "YourApplicationID",
  apiKey: "YourSearchOnlyAPIKey",
  useCookie: true,
});
Alternatively, you can provide your own anonymous user token on init.
JavaScript
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

userToken
string
Anonymous user identifier.See also: User token
⌘I