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

# Clicked object IDs after search

> Send a click event related to an Algolia request.

export const Legacy = ({title, href}) => {
  return <Note>

    This page documents an earlier version of the API client.
    For the latest version, see <a href={href}>{title}</a>.

    </Note>;
};

<Legacy title="Send events" href="/doc/libraries/sdk/methods/insights/push-events" />

**Required ACL:** `search`

Use this event to track when users click items in the search results.
If you're using Algolia to build your [category pages](/doc/guides/solutions/ecommerce/browse/tutorials/category-pages),
you'll also use the `clickedObjectIDsAfterSearch` event.

For details where this event is used, see [Event types](/doc/guides/sending-events/concepts/event-types).

**Related methods:**

* [`clickedObjectIDs`](/doc/libraries/sdk/v1/methods/clicked-object-ids): track click events **not related to Algolia requests**.
* [`sendEvents`](/doc/libraries/sdk/v1/methods/send-events): if you don't want to send real-time events.

## Examples

The following example sends one click event to the Algolia Insights API.
The event represents a user `user-123456` clicking on the item `objectID-1`,
which is at the second position in the results from the index `INDEX_NAME`

For more information about initializing the JavaScript Insights client `aa`,
see [Initialize the Insights client](/doc/libraries/search-insights/init).

<CodeGroup>
  ```cs C# theme={"system"}
  var insights = new InsightsClient(
    "YourApplicationID",
    "YourSearchOnlyAPIKey"
  ).User("user-123456");

  insights.ClickedObjectIDsAfterSearch(
    "Product Clicked",
    "YourIndexName",
    new List<string> { "objectID-1" },
    new List<uint> { 2 },
    "queryID"
  );
  ```

  ```go Go theme={"system"}
  client := insights.NewClient(
  	"YourApplicationID",
  	"YourSearchOnlyAPIKey",
  ).User("user-123456")

  res, err := client.ClickedObjectIDsAfterSearch(
  	"Product Clicked",
  	"YourIndexName",
  	[]string{"objectID-1"},
  	[]int{2},
  	"queryID",
  )
  ```

  ```java Java theme={"system"}
  UserInsightsClient insights = DefaultInsightsClient
      .create("YourApplicationID","YourSearchOnlyAPIKey")
      .user("user-123456");

  insights.clickedObjectIDsAfterSearch(
    "Product Clicked",
    "YourIndexName",
    Arrays.asList("objectID-1"),
    Arrays.asList(2L)),
    "queryID");
  ```

  ```js JavaScript theme={"system"}
  // This requires the `search-insights` library

  aa("clickedObjectIDsAfterSearch", {
    userToken: "anonymous-123456", // required for Node.js
    authenticatedUserToken: "user-123456",
    eventName: "Product Clicked",
    index: "YourIndexName",
    queryID: "queryID",
    objectIDs: ["objectID-1"],
    positions: [2],
  });
  ```

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

  clientInsights.User(userToken).clickedObjectIDsAfterSearch(
      indexName = IndexName("YourIndexName"),
      eventName = EventName("Product Clicked"),
      objectIDs = listOf(ObjectID("objectID-1")),
      positions = listOf(2),
      queryID = QueryID("queryID")
  )
  ```

  ```php PHP theme={"system"}
  $insights = Algolia\AlgoliaSearch\InsightsClient::create(
    'YourApplicationID',
    'YourSearchOnlyAPIKey'
  );

  $insights->user("user-123456")->clickedObjectIDsAfterSearch(
    'Product Clicked',
    'YourIndexName',
    ['objectID-1'],
    [2],
    'queryID'
  );
  ```

  ```python Python theme={"system"}
  insights = InsightsClient.create("YourApplicationID", "YourSearchOnlyAPIKey")

  insights.user("user-123456").clicked_object_ids_after_search(
      "Product Clicked", "YourIndexName", ["objectID-1"], [2], "queryID"
  )
  ```

  ```ruby Ruby theme={"system"}
  insights = Algolia::Insights::Client.create("YourApplicationID", "YourSearchOnlyAPIKey")

  insights.user("user-123456").clicked_object_ids_after_search(
    "Product Clicked",
    "YourIndexName",
    ["objectID-1"],
    [2],
    "queryID"
  )
  ```

  ```scala Scala theme={"system"}
  client.execute {
    send event ClickedObjectIDsAfterSearch(
      "user-123456",
      "Product Clicked",
      "YourIndexName",
      Seq("objectID-1"),
      Seq(2),
      "queryID"
    )
  }
  ```

  ```swift Swift theme={"system"}
  Insights.register(
    appId: "YourApplicationID",
    apiKey: "YourSearchOnlyAPIKey",
    userToken: "user-123456"
  )

  Insights.shared?.clickedAfterSearch(
    eventName: "Product Clicked",
    indexName: "YourIndexName",
    objectIDs: ["objectID-1"],
    positions: [2],
    queryID: "queryID"
  )
  ```
</CodeGroup>

## Parameters

<ParamField body="eventName" type="string" required>
  Name of the specific event.

  **Format:** 1-64 ASCII characters, except control characters.

  To maximize the impact of your events,
  use consistent event names and consistent formatting,
  for example, "Product Added To Cart" (always in title case).

  For example, you can adopt Twilio Segment's [object-action framework](https://segment.com/academy/collecting-data/naming-conventions-for-clean-data/#the-object-action-framework).
</ParamField>

<ParamField body="indexName" type="string" required>
  Name of the Algolia index.

  **Format**: same as the index name used by the search engine.

  Some API clients use `index` instead of `indexName`.
</ParamField>

<ParamField body="objectIDs" type="string[]" required>
  List of object IDs for records of an Algolia index.

  You can include up to 20 object IDs.
</ParamField>

<ParamField body="positions" type="string[]" required>
  Positions of the clicked results in the search results.
  This property is required for **click events** with `queryID`.
  The first search result has a position of 1 (not 0).

  You must provide one `position` for each object ID.

  Algolia uses this parameter to calculate the [average click position](/doc/guides/search-analytics/concepts/metrics#click-position).

  The position is absolute, and not relative, to any results page.
  For example, if there are 10 results per page,
  the position of the third record of the second results page is 13.
  Since [`page`](/doc/api-reference/api-parameters/page) starts at 0,
  you can use the following formula: `positionOnPage + page * hitsPerPage`.
</ParamField>

<ParamField body="queryID" type="string" required>
  Unique identifier for a search query.

  A `queryID` is required for events related to search or browse requests.

  If you add [`clickAnalytics: true`](/doc/api-reference/api-parameters/clickAnalytics)
  as a search request parameter,
  the `queryID` is included in the API response.

  See also: [Keep track of query IDs](/doc/guides/sending-events/guides/queryid)
</ParamField>

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

  See also: [User token](/doc/guides/sending-events/concepts/usertoken)
</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>
