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

# Enabling Personalization

> Learn how to enable Personalization with or without an InstantSearch implementation.

export const SearchRequest = () => <Tooltip tip="A search request is a single HTTP call to the Algolia Search API that can run one or more search operations. It can include multiple queries, for example, when querying several indices at once.">
    search request
  </Tooltip>;

export const Index = () => <Tooltip tip="An Algolia index is a searchable dataset that consists of records and configuration settings. These settings define how the records are searched and ranked.">
    index
  </Tooltip>;

export const Affinity = () => <Tooltip tip="Affinity is a preference score that Algolia calculates for each user based on their behavior. It reflects how likely a user is to prefer a specific facet-value pair and helps personalize their search results." cta="Affinity" href="/doc/guides/personalization/advanced-personalization/configure/prerequisites/consider-requirements-limits#affinities">
    affinity
  </Tooltip>;

To give your users a personalized experience, you need to include the [`enablePersonalization`](/doc/api-reference/api-parameters/enablePersonalization) and [`userToken`](/doc/api-reference/api-parameters/userToken) parameters in the <SearchRequest />.
How you do this depends on your Algolia implementation and whether you use [InstantSearch](/doc/guides/building-search-ui/what-is-instantsearch/js).

You can also set [`enablePersonalization`](/doc/api-reference/api-parameters/enablePersonalization) in your <Index /> settings instead of sending it as a search parameter.
This way, every search on your index uses Personalization, unless you override this at query time by setting the [`enablePersonalization`](/doc/api-reference/api-parameters/enablePersonalization) parameter to `false`.

If you set [`enablePersonalization`](/doc/api-reference/api-parameters/enablePersonalization) as an index setting,
you still need to include a user's [`userToken`](/doc/api-reference/api-parameters/userToken) in your search requests.
If you don't include the [`userToken`](/doc/api-reference/api-parameters/userToken),
Algolia doesn't know which user's <Affinity /> profile to apply to personalize the results.

## Enable Personalization with InstantSearch

If you are using [InstantSearch](/doc/guides/building-search-ui/what-is-instantsearch/js), it's best to enable Personalization by using the [`configure`](/doc/api-reference/widgets/configure/js) widget. The [`configure`](/doc/api-reference/widgets/configure/js) widget lets you provide raw search parameters to the Algolia API without rendering anything.

Using the [`configure`](/doc/api-reference/widgets/configure/js) widget, you can set the [`enablePersonalization`](/doc/api-reference/api-parameters/enablePersonalization) to `true` and include the [`userToken`](/doc/api-reference/api-parameters/userToken). The [`userToken`](/doc/api-reference/api-parameters/userToken) should match the one you're using to [send click and conversion events](/doc/guides/sending-events/getting-started) for a particular user.

<CodeGroup>
  ```js JavaScript theme={"system"}
  instantsearch.widgets.configure({
    enablePersonalization: true,
    userToken: "user-1234",
  });
  ```

  ```swift Swift theme={"system"}
  searcher.request.query.enablePersonalization = true
  searcher.request.query.userToken = 'user-1234'
  ```

  ```vue Vue theme={"system"}
  <template>
    <ais-instant-search
      index-name="instant_search"
      :search-client="searchClient"
    >
      <ais-configure :clickAnalytics="true" userToken="user-1234" />
    </ais-instant-search>
  </template>

  <script>
    import { liteClient as algoliasearch } from 'algoliasearch/lite';

    export default {
      data() {
        return {
          searchClient: algoliasearch(
            'undefined',
            'undefined'
          ),
        };
      },
    };
  </script>
  ```

  ```jsx React theme={"system"}
  import { liteClient as algoliasearch } from "algoliasearch/lite";
  import { InstantSearch } from "react-instantsearch-dom";

  const searchClient = algoliasearch("undefined", "undefined");

  const App = () => (
    <InstantSearch indexName="instant_search" searchClient={searchClient}>
      <Configure enablePersonalization={true} userToken="user-1234" />
    </InstantSearch>
  );
  ```

  ```kotlin Android theme={"system"}
  searcher.query.query.enablePersonalization = true
  searcher.query.userToken = 'user-1234'
  ```
</CodeGroup>

For more information, see [User token](/doc/guides/sending-events/concepts/usertoken).

## Enable Personalization using API clients

If you're using one of the API clients to make search requests,
you can include [`enablePersonalization`](/doc/api-reference/api-parameters/enablePersonalization) and [`userToken`](/doc/api-reference/api-parameters/userToken) as parameters in the [`search`](/doc/libraries/sdk/v1/methods/search) method.
The [`userToken`](/doc/api-reference/api-parameters/userToken) should match the one you're using to [send events](/doc/guides/sending-events/getting-started) for a particular user.

<CodeGroup>
  ```cs C# theme={"system"}
  var response = await client.SearchSingleIndexAsync<Hit>(
    "INDEX_NAME",
    new SearchParams(new SearchParamsObject { Query = "query", EnablePersonalization = true })
  );
  ```

  ```dart Dart theme={"system"}
  final response = await client.searchSingleIndex(
    indexName: "INDEX_NAME",
    searchParams: SearchParamsObject(
      query: "query",
      enablePersonalization: true,
    ),
  );
  ```

  ```go Go theme={"system"}
  response, err := client.SearchSingleIndex(client.NewApiSearchSingleIndexRequest(
    "INDEX_NAME").WithSearchParams(search.SearchParamsObjectAsSearchParams(
    search.NewEmptySearchParamsObject().SetQuery("query").SetEnablePersonalization(true))))
  if err != nil {
    // handle the eventual error
    panic(err)
  }
  ```

  ```java Java theme={"system"}
  SearchResponse response = client.searchSingleIndex(
    "INDEX_NAME",
    new SearchParamsObject().setQuery("query").setEnablePersonalization(true),
    Hit.class
  );
  ```

  ```js JavaScript theme={"system"}
  const response = await client.searchSingleIndex({
    indexName: 'indexName',
    searchParams: { query: 'query', enablePersonalization: true },
  });
  ```

  ```kotlin Kotlin theme={"system"}
  var response =
    client.searchSingleIndex(
      indexName = "INDEX_NAME",
      searchParams = SearchParamsObject(query = "query", enablePersonalization = true),
    )
  ```

  ```php PHP theme={"system"}
  $response = $client->searchSingleIndex(
      'INDEX_NAME',
      ['query' => 'query',
          'enablePersonalization' => true,
      ],
  );
  ```

  ```python Python theme={"system"}
  response = client.search_single_index(
      index_name="INDEX_NAME",
      search_params={
          "query": "query",
          "enablePersonalization": True,
      },
  )
  ```

  ```ruby Ruby theme={"system"}
  response = client.search_single_index(
    "INDEX_NAME",
    Algolia::Search::SearchParamsObject.new(query: "query", enable_personalization: true)
  )
  ```

  ```scala Scala theme={"system"}
  val response = Await.result(
    client.searchSingleIndex(
      indexName = "INDEX_NAME",
      searchParams = Some(
        SearchParamsObject(
          query = Some("query"),
          enablePersonalization = Some(true)
        )
      )
    ),
    Duration(100, "sec")
  )
  ```

  ```swift Swift theme={"system"}
  let response: SearchResponse<Hit> = try await client.searchSingleIndex(
      indexName: "INDEX_NAME",
      searchParams: SearchSearchParams.searchSearchParamsObject(SearchSearchParamsObject(
          query: "query",
          enablePersonalization: true
      ))
  )
  ```
</CodeGroup>

## Enable Personalization using the dashboard

You can set [`enablePersonalization`](/doc/api-reference/api-parameters/enablePersonalization) as an index setting for the indices you want to personalize results for. This setting automatically sets [`enablePersonalization`](/doc/api-reference/api-parameters/enablePersonalization)`:true` for any search requests made on this index. If you want to turn Personalization off at query time for some reason, you can include [`enablePersonalization`](/doc/api-reference/api-parameters/enablePersonalization)`:false` on those search requests.

Go to [**Indices** section of the dashboard](https://dashboard.algolia.com/explorer/) and then **Configuration** » **Relevance Essentials** » **Personalization** for each index you want to enable Personalization on.
Here, you can set [`enablePersonalization`](/doc/api-reference/api-parameters/enablePersonalization) to `true`.

Remember that unless you include a valid [`userToken`](/doc/api-reference/api-parameters/userToken), the engine can't personalize results. **Even if you enable Personalization on the dashboard, you still need to provide the [`userToken`](/doc/api-reference/api-parameters/userToken) using either InstantSearch or an API Client.**

That's why you don't automatically see personalized results if you are testing queries in the [**Browse** section](https://dashboard.algolia.com/explorer/) of an index where you've enabled [`enablePersonalization`](/doc/api-reference/api-parameters/enablePersonalization) as an index setting. While you can add the [`userToken`](/doc/api-reference/api-parameters/userToken) by selecting **+Add Query Parameter**, it's best to [simulate Personalization](/doc/guides/personalization/classic-personalization/personalizing-results/in-depth/configuring-personalization#simulating-personalization) using the dedicated [Personalization simulator](/doc/guides/personalization/classic-personalization/personalizing-results/in-depth/configuring-personalization#simulating-personalization). The simulator lets you compare personalized and non-personalized results and provides information to explain how Personalization affected the results.
