> ## Documentation Index
> Fetch the complete documentation index at: https://www.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 later 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 on setting up 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 a user logs in, set the authenticated user token.
Use the user ID from your system.

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

Algolia now sends both the anonymous and authenticated tokens with each event.
This keeps data from before users signed in.

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>
