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

# Set authenticated user token

> Set the authenticated user token for all subsequent events sent to the Algolia Insights API.

**Required ACL:** `search`

Use this method to automatically send the `authenticatedUserToken` with every event.
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",
  useCookie: true,
});
```

When user logs in, set the authenticated user token to the user ID coming from your system.

```js JavaScript icon=code theme={"system"}
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`.

```js JavaScript icon=code theme={"system"}
aa("setAuthenticatedUserToken", undefined);
```

## Parameters

<ParamField body="authenticatedUserToken" type="string | undefined" required>
  Pseudonymous identifier for authenticated users.

  <Warning>
    Don't include personally identifiable information in user tokens.
  </Warning>

  See also: [User token](/doc/guides/sending-events/concepts/usertoken)
</ParamField>
