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

# Category Viewed

## Category Viewed (`category_viewed`)

**Purpose:**
Track when a user lands on or refreshes a category listing page to view products in that category.

**When to Fire:**
After your page or API loads the category data and product SKUs typically on page load or when your view changes to a category view.

**Payload Schema:**

| Field             | Type             | Description                                                                                       |
| ----------------- | ---------------- | ------------------------------------------------------------------------------------------------- |
| `category_id`     | string or number | Unique identifier of the category.                                                                |
| `category_name`   | string           | Human‑readable category name.                                                                     |
| `sku`             | array of strings | Flat array of SKUs for all products in this category.                                             |
| `search_source`   | string           | For suggestion clicks, pass the autocomplete category key from the response (e.g., `"category"`). |
| `used_suggestion` | string           | The exact suggestion text the user clicked (e.g., "shirts", "jeans").                             |
| `facets`          | array            | Active filters (e.g. size, brand)—each `{ field, value }`. Use an empty array if none.            |
| `request_id`      | string           | Unique identifier for the search request (x-request-id from response headers).                    |
| `page_depth`      | string           | Current page number (1, 2, 3, etc.).                                                              |

**Example:**

```js theme={null}
// Assume these variables are populated from your category response and UI state:
const categoryId      = 'cat123';
const categoryName    = 'Running Shoes';
const selectedFacets  = [];       // e.g. [{ field: 'size', value: '10' }]
const requestId       = categoryResponse.headers.get('x-request-id');
const currentPage     = 1;        // Current page number (1, 2, 3, etc.)
const products        = [
  { sku: 'RS-001', name: 'Lightweight Runner' },
  { sku: 'RS-002', name: 'Marathon Pro' }
];

ExpAnalyticsService.trackCategoryViewed({
  category_id: categoryId,
  category_name: categoryName,
  sku: products.map(p => p.sku),
  used_suggestion: usedSuggestion,
  search_source: searchSource,
  facets: selectedFacets,
  request_id: requestId,
  page_depth: currentPage
});
```
