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

# Init

> Initialize the Search Insights client.

**Required ACL:** `search`

To initialize the Insights client,
you need your Algolia application ID and your API key with `search` permissions.
You can find both in your [Algolia dashboard](https://dashboard.algolia.com/account/api-keys).

<Info>
  Starting from v2.4.0, you an also pass credentials as headers for each call.
  If you're using the client with InstantSearch or Autocomplete,
  credentials are inferred from the search client.
</Info>

Use the `init` method to set global options for the Insights client,
for example, set the `userToken` parameter to send it with every event.

To update parameters later, use the [`partial`](#param-partial) option.

For more information about events, see [Click and conversion events](/doc/guides/sending-events).

If the user is signed in, set the authenticated user token,
which should come from your system.

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

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

If the user isn't identified,
you can let the Insights API client generate an anonymous user token,
and persist it in the cookies.

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

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

To set the authenticated user token later,
use [`setAuthenticatedUserToken`](/doc/libraries/search-insights/set-authenticated-user-token).

## Parameters

<ParamField body="apiKey" type="string">
  Search API key of your Algolia application.
</ParamField>

<ParamField body="appId" type="string">
  Identifier of your Algolia application.
</ParamField>

<ParamField body="authenticatedUserToken" type="string">
  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>

<ParamField body="cookieDuration" type="integer" default="15,552,000,000">
  Cookie duration in milliseconds. The default is 6 months.

  For [Personalization](/doc/guides/personalization/classic-personalization/what-is-personalization),
  at least 3 months (7,776,000,000 ms) are recommended.
</ParamField>

<ParamField body="host" type="string">
  URL of your server for routing requests before forwarding them to Algolia.
</ParamField>

<ParamField body="partial" type="boolean">
  Whether to partially update the configuration while preserving existing options.
  Use this to update the settings of a running client without having to specify all options again.
</ParamField>

<ParamField body="region" type="enum<string>">
  Analytics region, one of:

  * `de`
  * `us`
</ParamField>

<ParamField body="useCookie" type="boolean" default={false}>
  Whether to store the anonymous user token in a browser cookie.

  In some jurisdictions, you need to [obtain user consent](/doc/guides/sending-events/concepts/usertoken#algolia-cookie)
  before using cookies.
  Make sure to obtain it *before* you set this option to `true`.
  Storing cookies on a user's device may require consent.

  Set this parameter to `true` when using [Personalization](/doc/guides/personalization/classic-personalization/what-is-personalization).
  See also: [Persistent user token](/doc/guides/sending-events/concepts/usertoken#persistent-user-token)
</ParamField>

<ParamField body="userHasOptedOut" type="boolean" default={false}>
  Whether to exclude users who opted out from analytics.

  Set this parameter to `true` when users request to not be tracked.
</ParamField>

<ParamField body="userToken" type="string">
  Anonymous user identifier.

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