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.
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 parameter in the init method.
aa("init", {
appId: "YourApplicationID",
apiKey: "YourSearchOnlyAPIKey",
useCookie: true,
});
Alternatively, you can provide your own anonymous user token on init.
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
Last modified on February 10, 2026