# `events`

Use event hooks to get notified about various user events in your API reference documentation.
This feature provides access to in-page analytics.

**Redoc CE**

Redoc CE triggers these events: `codeSamplesLanguageSwitch`, `targetServerSwitch`, and `codeSamplesCopy`.
The `tryItOpen` and `tryItSent` events require the **Try it** panel, which is not part of Redoc CE.

Each event provides information about a specific event as well as some basic information:

```typescript
    eventType: string;
    resource: string;
    action: string;
    operationId?: string;
    operationPath: string;
    operationHttpVerb: string;
    operationSummary?: string;
```

## Options

| Option | Type | Description |
| --- | --- | --- |
| codeSamplesLanguageSwitch | string | A function called when the user switches to a different language tab in the code samples section. Provides information about the selected language (lang) and an optional example ID (exampleId). |
| tryItOpen | string | A function that triggers when the user opens the “Try it” panel. Captures actions like opening the panel or navigating using the override links. |
| targetServerSwitch | string | A function invoked when the user changes the target server selection. Provides the updated server URL (serverUrl). |
| tryItSent | string | A function called when a request sent from the **Try it** panel receives a response, whatever its HTTP status. The event's `action` is `Sent`. |
| codeSamplesCopy | string | A function that triggers when a user copies request or response samples within the Reference docs UI. Captures details such as the sample type (request or responses), example ID (if applicable), code sample language (`lang`), and label (`label`). |

## Examples

The following example show the usage of the `events` configuration:

```yaml
openapi:
  events:
    codeSamplesLanguageSwitch: '({ lang, label, exampleId}) => {
      console.log(`Switched to language: ${lang}`);
    }'
    tryItOpen: '() => {
      console.log(`Try it panel opened`);
    }'
    targetServerSwitch: '({ serverUrl }) => {
      console.log(`Switched to server: ${serverUrl}`);
    }'
```

## Resources

- **[OpenAPI configuration](/docs/platform/config/openapi)** - Complete guide to OpenAPI configuration options for customizing API reference documentation
- **[OpenAPI Specification](https://spec.openapis.org/oas/latest.html)** - Official OpenAPI Specification documentation for understanding API description standards
- **[OpenAPI visual reference](https://redocly.com/learn/openapi/openapi-visual-reference)** - Visual guide to OpenAPI specification structure and event configuration principles
- **[Configuration options](/docs/platform/config)** - Explore other project configuration options for comprehensive documentation customization
