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

# Selected Text Events

> Track selected text events in LangWatch to understand user behavior and improve LLM performance across AI agent evaluations.

Selected text events allow you to track when a user selects text generated by your LLM application, indicating the response was useful enough to be copied and used elsewhere.

## REST API Specification

### Endpoint

`POST /api/track_event`

### Headers

* `X-Auth-Token`: Your LangWatch API key.

### Request Body

```javascript theme={null}
{
  "trace_id": "id of the message the user selected",
  "event_type": "selected_text",
  "metrics": {
    "text_length": 120 // Length of the selected text in characters
  },
  "event_details": {
    "selected_text": "The selected text content"
  },
  "timestamp": 1617981376000, // Unix timestamp in milliseconds
}
```

### Example

```bash theme={null}
curl -X POST "https://app.langwatch.ai/api/track_event" \\
     -H "X-Auth-Token: your_api_key" \\
     -H "Content-Type: application/json" \\
     -d '{
       "trace_id": "trace_Yy0XWu6BOwwnrkLtQh9Ji",
       "event_type": "selected_text",
       "metrics": {
         "text_length": 120
       },
       "event_details": {
         "selected_text": "The capital of France is Paris."
       },
       "timestamp": 1617981376000
     }'
```

The `text_length` metric is mandatory and should reflect the length of the selected text. The `selected_text` field in `event_details` is optional if you also want to capture the actual text that was selected by the user.
