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

# Viewed filters

> Send a view event to capture the active filters for items a user viewed.

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`

When users browse a category page,
they see content filtered on that specific category.

To capture the active filters, send a `viewEvent`.

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

## Examples

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.ViewedFilters(
    "Brand Viewed",
    "YourIndexName",
    new List<string> { "brand:apple", "brand:google" }
  );
  ```

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

  res, err := client.ViewedFilters(
  	"Brand Viewed",
  	"YourIndexName",
  	[]string{"brand:apple", "brand:google"},
  )
  ```

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

  insights.viewedFilters(
    "Brand Viewed",
    "YourIndexName",
    Arrays.asList("brand:apple", "brand:google")
  );
  ```

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

  aa('viewedFilters', {
    userToken: 'anonymous-123456', // required for Node.js
    authenticatedUserToken: 'user-123456',
    index: 'YourIndexName',
    eventName: 'Brand Viewed',
    filters: [ 'brand:apple' ]
  });
  ```

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

  clientInsights.User(userToken).viewedFilters(
      indexName = IndexName("YourIndexName"),
      eventName = EventName("Brand Viewed"),
      filters = listOf(Filter.Facet(Attribute("brand"), "apple"))
  )
  ```

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

  $insights->user("user-123456")->viewedFilters(
    'Brand Viewed',
    'YourIndexName',
    ['brand:google']
  );
  ```

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

  insights.user("user-123456").viewed_filters(
      "Brand Viewed", "YourIndexName", ["brand:apple", "brand:google"]
  )
  ```

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

  insights.user("user-123456").viewed_filters(
    "Brand Viewed",
    "YourIndexName",
    ["brand:apple", "brand:google"]
  )
  ```

  ```scala Scala theme={"system"}
  client.execute {
    send event ViewedFilters(
      "user-123456",
      "Brand Viewed",
      "YourIndexName",
      Seq("brand:apple", "brand:google")
    )
  }
  ```

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

  Insights.shared?.viewed(
    eventName: "Brand Viewed",
    indexName: "YourIndexName",
    filters: ["brand:apple", "brand:google"]
  )
  ```
</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="filters" type="string[]" required>
  List of facet filters.

  You can include up to 10 filters.

  **Format:** `${attribute}:${value}`—for example, `brand:apple`.
  Both the `attribute` and `value` in each facet filter must be [URL-encoded](https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding) individually and separated by a `:`, such as, `"discount:10%25"`.
</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="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>
