> ## Documentation Index
> Fetch the complete documentation index at: https://algolia.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get user token

> Get the anonymous user token from the Insights API Client state.

**Required ACL:** `search`

Use this method to keep track of the anonymous user token generated by the Insights API Client.
For more information, see [User token](/doc/guides/sending-events/concepts/usertoken).

## Examples

For more information about initializing the JavaScript Insights client `aa`,
see [Initialize the Insights client](/doc/libraries/search-insights/init).

```js JavaScript icon=code theme={"system"}
import aa from "search-insights";

aa("init", {
  appId: "YourApplicationID",
  apiKey: "YourSearchOnlyAPIKey",
});
```

Then, retrieve the generated user token.

```js JavaScript icon=code theme={"system"}
aa("getUserToken", {}, (err, userToken) => {
  if (err) {
    console.error(err);
    return;
  }

  console.log(userToken);
});
```

## Parameters

<ParamField body="callback" type="(err: Error, userToken: string) => void">
  The function called with a possible error and the user token.
</ParamField>

<ParamField body="options" type="object">
  The options for retrieving the user token.

  Pass an empty object, since this argument isn't used.
</ParamField>
