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

# userToken

> Pseudonymous user identifier

export const Setting = ({type, default: defaultValue, defaultNote, scope, min, max, formerly}) => {
  const renderedDefault = defaultValue === '' ? '""' : defaultValue;
  const renderedNote = defaultNote ? `(${defaultNote})` : '';
  return <ul>
      <li><strong>Type:</strong> <code>{type}</code></li>
      <li><strong>Default:</strong> <code>{renderedDefault}</code>{renderedNote}</li>
      {min && <li><strong>Min:</strong> <code>{min}</code></li>}
      {max && <li><strong>Max:</strong> <code>{max}</code></li>}
      <li><strong>Scope:</strong> <a href="/doc/api-reference/api-parameters"><code>{scope}</code></a></li>
      {formerly && <li>
          <strong>Deprecated name:</strong> <code>{formerly}</code>
        </li>}
    </ul>;
};

<Setting type="string" default="" defaultNote="user IP address" scope="search" />

The `userToken` parameter links a search request to a specific pseudonymous user.\
It enables features that rely on user-level tracking, including:

* [Analytics](/doc/guides/search-analytics/guides/usertoken)
* [NeuralSearch](/doc/guides/ai-relevance/neuralsearch/get-started)
* [Personalization](/doc/guides/personalization/classic-personalization/what-is-personalization)

## Usage

* If not set explicitly, the user's IP address is used as a fallback identifier.
* The same token should be used across all search, click, and conversion events for consistent behavior tracking.
* User token must not contain personally identifiable information.

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

## Example

<AccordionGroup>
  <Accordion title="Current API clients" defaultOpen="true">
    <CodeGroup>
      ```cs C# theme={"system"}
      var response = await client.SearchSingleIndexAsync<Hit>(
        "INDEX_NAME",
        new SearchParams(new SearchParamsObject { Query = "query", UserToken = "123456" })
      );
      ```

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

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

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

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

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

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

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

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

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

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

  <Accordion title="Legacy API clients">
    <CodeGroup>
      ```cs C# theme={"system"}
      Query query = new Query("query");
      query.UserToken = "123456";
      ```

      ```go Go theme={"system"}
      res, err := index.Search(
      	"query",
      	opt.UserToken("123456"),
      )
      ```

      ```java Java theme={"system"}
      Query query = new Query("query").setUserToken("123456")
      ```

      ```js JavaScript theme={"system"}
      index
        .search("query", {
          userToken: "123456",
        })
        .then(({ hits }) => {
          console.log(hits);
        });
      ```

      ```kotlin Kotlin theme={"system"}
      val query = query("query") {
          userToken = UserToken("123456")
      }

      index.search(query)
      ```

      ```php PHP theme={"system"}
      $index->search('query', ['userToken' => '123456'])
      ```

      ```python Python theme={"system"}
      index.search("query", {"userToken": "123456"})
      ```

      ```ruby Ruby theme={"system"}
      index.search("query", {userToken: "123456"})
      ```

      ```scala Scala theme={"system"}
      client.execute {
        search into "myIndex" query Query(
          query = Some("query"),
          userToken = Some("123456")
        )
      }
      ```

      ```swift Swift theme={"system"}
      let query = Query("query")
        .set(\.userToken, to: "123456")

      index.search(query: query) { result in
        if case .success(let response) = result {
          print("Response: \(response)")
        }
      }
      ```
    </CodeGroup>
  </Accordion>
</AccordionGroup>
