Last updated

events

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

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

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

Options

OptionTypeDescription
codeSamplesLanguageSwitchfunctionCalled 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).
tryItOpenfunctionTriggered when the user opens the “Try it” panel. Captures actions like opening the panel or navigating using the override links.
targetServerSwitchfunctionInvoked when the user changes the target server selection. Provides the updated server URL (serverUrl).
tryItSentfunctionCalled when the user clicks the “Send” button in the “Try it” panel. Captures whether the request was successfully sent (Sent) or if there was a validation failure (ValidationFailed).
panelTogglefunctionRecords when a user expands or collapses any panel in the Reference docs UI (for example, request, responses, request samples, or response samples). Includes details about the panel type (panelType) and its state (expanded or collapsed).
codeSamplesCopyfunctionTriggered 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:

redocly.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}`);
    }'
  • openapi - Learn more about using openapi configuration.

Resources