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

# Events

Widget events are simple JSON objects that are emitted by the BeyondWords widget. They contain information about the current state of the widget. They are separate from analytics events which contain information about user engagement.

You can listen to widget events and perform your own actions after they are processed by the widget in its [RootController](https://github.com/BeyondWords-io/player/blob/main/src/controllers/rootController.ts). Events have a set of fields that are always present and some events contain additional fields. Here is an example:

```javascript Example event theme={null}
{
  id: "51178a37-d5a7-4d75-9a12-a26eabfe7839",
  type: "PressedPlaylistItem",
  description: "A playlist item was pressed.",
  index: 3,
  initiatedBy: "user",
  emittedFrom: "inline-player",
  status: "handled",
  createdAt: "2023-01-01T12:00:00.000Z",
  processedAt: "2023-01-01T12:00:00.005Z",
  changedProps: {
    contentIndex: { previousValue: 0, currentValue: 3 },
  },
}
```

For the above example, the 'index' field additional and is specific to the PressedPlaylistItem event.

All of the other fields are present in every event. Their schema is explained below.

## Event schema

* `id`: A random UUID generated and assigned to the event at creation.
* `type`: The type of event, see the table below for a listing of event types.
* `description`: A short human-readable description of the event.
* `initiatedBy`: Who initiated the event, one of: `{ user, media, browser, media-session-api, google-ima-sdk }`
* `emittedFrom`: Which interface emitted the event, one of: `{ inline-player, bottom-widget, segment, segment-widget }`
* `status`: The status of the event, one of: `{ handled, ignored-due-to-advert, ignored-due-to-intro-outro, ignored-due-to-scrubbing, ignored-due-to-precedence }`
* `createdAt`: The time when the event was created in simplified extended ISO 8601 format.
* `processedAt`: The time when the event was processed in simplified extended ISO 8601 format.
* `changedProps`: An object listing the widget properties that were changed by the event.

It is recommended to not depend on `changedProps` and additional event fields (e.g., index) since these might change.

Instead, query the widget props directly using the [Widget API](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/widget-api.md) when listening to events.

## Event types

The following table lists all event types emitted by the widget.

Initiators denoted with a plus `(+)` can also be initiated by media-session-api, e.g., using playback controls on a phone lock screen.

Initiators denoted with a star `(*)` can also be initiated by google-ima-sdk when VAST ads are playing.

To inspect the events further, it is recommended you [listen to `"<any>"` event](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/events#listen-to-events) and console log them.

| Type | Initiator | Description |
| - | - | - |
| IdentifiersChanged | browser | The Player's content identifiers changed. |
| ContentAvailable | browser | Content was loaded into the player and is ready to be played. |
| NoContentAvailable | browser | No published and processed content is available for the identifiers. |
| AgentAvailableWithoutContent | browser | No content matched the identifiers, so the widget shows your agent on its own. |
| FullScreenModeUpdated | browser | The browser entered or exited full screen mode. |
| AgentClientChanged | browser | The agent client was replaced, so subscribers must resubscribe to the new one. |
| PressedPlay | user+ | The play button was pressed. |
| PressedPause | user+ | The pause button was pressed. |
| PressedChangeRate | user | The change playback rate button was pressed. |
| PressedEnterOnChangeRate | user | The enter key was pressed while change playback rate was focussed. |
| PressedSpaceOnChangeRate | user | The space key was pressed while change playback rate was focussed. |
| PressedUpOnChangeRate | user | The up key was pressed while change playback rate was focussed. |
| PressedRightOnChangeRate | user | The right key was pressed while change playback rate was focussed. |
| PressedDownOnChangeRate | user | The down key was pressed while change playback rate was focussed. |
| PressedLeftOnChangeRate | user | The left key was pressed while change playback rate was focussed. |
| PressedChangeVersion | user | A version was selected from the version menu. |
| PressedPrevSegment | user+ | The previous segment button was pressed. |
| PressedNextSegment | user+ | The next segment button was pressed. |
| PressedSeekBack | user+ | The seek backward button was pressed. |
| PressedSeekAhead | user+ | The seek ahead button was pressed. |
| PressedPrevTrack | user+ | The previous track button was pressed. |
| PressedNextTrack | user+ | The next track button was pressed. |
| PressedAdvertLink | user | The ad link was pressed to open the click-through URL in a new tab. |
| PressedAdvertButton | user | The ad button was pressed to open the click-through URL in a new tab. |
| PressedAdvertImage | user | The ad image was pressed to open the ad in a new tab. |
| PressedAdvertVideo | user | The video background was pressed to open the ad in a new tab. |
| PressedBeyondWords | user | The BeyondWords logo was pressed to open the BeyondWords website in a new tab. |
| PressedSourceUrl | user | The source URL button was pressed to open the source article in a new tab. |
| VisibilityChanged | user | The player was scrolled into or out of view. |
| PressedVideoBackground | user | The video background was pressed. |
| PressedEnterOnProgressBar | user | The enter key was pressed while the progress bar was focussed. |
| PressedSpaceOnProgressBar | user | The space key was pressed while the progress bar was focussed. |
| PressedEnterOnProgressCircle | user | The enter key was pressed while the progress circle was focussed. |
| PressedSpaceOnProgressCircle | user | The space key was pressed while the progress circle was focussed. |
| PressedLeftOnProgressBar | user | The left key was pressed while the progress bar was focussed. |
| PressedRightOnProgressBar | user | The right key was pressed while the progress bar was focussed. |
| PressedLeftOnProgressCircle | user | The left key was pressed while the progress circle was focussed. |
| PressedRightOnProgressCircle | user | The right key was pressed while the progress circle was focussed. |
| PressedProgressBar | user | The progress bar was pressed at some ratio. |
| ScrubbedProgressBar | user+ | The user pressed on the progress bar then dragged. |
| FinishedScrubbingProgressBar | user | The user let go after scrubbing the progress bar. |
| PressedMaximize | user | The maximize button was pressed. |
| PressedPlaylistItem | user | A playlist item was pressed. |
| PressedDownload | user | The download button next to a playlist item was pressed. |
| PressedTogglePlaylist | user | The toggle playlist button was pressed. |
| PressedCloseWidget | user | The close widget button was pressed. |
| PressedSegment | user | The user pressed on a segment in the article. |
| HoveredSegmentUpdated | user | The user hovered over a different segment in the article. |
| CurrentSegmentUpdated | media | The media's current segment was updated. |
| SegmentLimitReached | media | The media's segment limit was reached. |
| MetadataLoaded | media | The media finished loading its metadata. |
| MediaLoaded | media | The media finished loading its first frame of data. |
| MediaSeeked | media | The media completed the seek operation. |
| DurationUpdated | media\* | The media's duration was updated. |
| CurrentTimeUpdated | media | The media's current time was updated. |
| PlaybackPaused | media\* | The media became paused at its current playback time. |
| PlaybackRateUpdated | media | The media's playback rate was updated. |
| PlaybackPlaying | media | The media began playing from its current playback time. |
| PlaybackEnded | media\* | The media finished playing because it reached the end. |
| PlaybackNotAllowed | media | The media can't play because there was no user event. |
| PlaybackErrored | media\* | The media failed to play. |
| CompanionAdvertChanged | media\* | The companion ad associated with the VAST ad changed. |

## Listen to events

The widget emits events in response to user actions, playback time updates, entering full screen, etc.

You can listen to these events in your JavaScript code:

```javascript theme={null}
const player = BeyondWords.Player.instances()[0];

player.addEventListener("<any>", console.log);
```

The code above registers an event listener that listens to any event and logs it to the console.

If you only want to listen to a single event type, provide its name:

```javascript theme={null}
player.addEventListener("PressedPlay", console.log);

player.addEventListener("PlaybackEnded", console.log);
```

Events contain a standard set of fields such as `type` and `createdAt` and some contain additional fields.

See [Event schema](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/events.md#event-schema) and [Event types](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/events.md#event-types) for a full listing of event types and their fields.

### Clean up

The return value of `addEventListener` is a string that is a handle to the listener.

This allows you remove the listener, for example, if a React component is unmounted:

```javascript theme={null}
useEffect(() => {
  const listener = player.addEventListener("<any>", console.log);
  return () => player.removeEventListener("<any>", listener);
}, []);
```

Or when your Svelte component is unmounted:

```javascript theme={null}
onMount(() => {
  const listener = player.addEventListener("<any>", console.log);
  return () => player.removeEventListener("<any>", listener);
});
```

Otherwise, the callback function will continue to be called which may result in an error in your application.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.