> ## 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.

# JavaScript SDK

The BeyondWords JavaScript widget delivers [audio](https://docs.beyondwords.io/docs-and-guides/audio.md), [video](https://docs.beyondwords.io/docs-and-guides/audio/video.md), and your [agent](https://docs.beyondwords.io/docs-and-guides/agent.md) on any webpage. Install it with an embed script (quickest) or the NPM package (best for frameworks and build tools).

> [!TIP]
>
> Using [Magic Embed](https://docs.beyondwords.io/docs-and-guides/import-content/sources/magic-embed.md), [WordPress](https://docs.beyondwords.io/docs-and-guides/integrations/publishing-platforms/wordpress.md), or [Ghost](https://docs.beyondwords.io/docs-and-guides/integrations/publishing-platforms/ghost.md)? The widget may already be installed, so check your integration guide before adding the SDK manually.

## How it works

1. The SDK loads from `proxy.beyondwords.io` and creates a `BeyondWords.Player` instance.
2. You pass a **project ID** and one or more **content identifiers** (`contentId`, `sourceId`, `sourceUrl`, or `playlistId`).
3. The widget fetches content and settings from the [Widget API](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/widget-api.md), then renders the UI at your `target` element.
4. Appearance and behavior come from the **Widget** page in your project dashboard, unless overridden via [widget properties](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/properties.md).

## Before you begin

* A BeyondWords project with generated content.
* Your numeric **project ID** (from **Settings → Developers**).
* A **content identifier**: `contentId`, `sourceId`, `sourceUrl`, or `playlistId`. See [load content](#load-content) below.

## Install with an embed script

**1. Add a target element**

Place a `<div>` (or other element) where you want the widget to appear, or use `target: this` in the script tag to insert the widget immediately after the tag.

**2. Paste the embed script**

Add the script to your page HTML:

```html theme={null}
<script async defer
  src="https://proxy.beyondwords.io/npm/@beyondwords/player@latest/dist/umd.js"
  onload="new BeyondWords.Player({
    target: this,
    projectId: YOUR_PROJECT_ID,
    contentId: 'YOUR_CONTENT_ID',
  })">
</script>
```

Replace `YOUR_PROJECT_ID` with your numeric project ID and `'YOUR_CONTENT_ID'` with the content UUID.

The `async` and `defer` attributes let the rest of the page load while the SDK downloads. Setting `target: this` mounts the widget right after the script tag.

**3. Configure the widget**

Customize appearance on the **Widget** page, or pass [widget properties](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/properties.md) in the `onload` handler to override dashboard defaults.

## Install with NPM

**1. Install the package**

```bash theme={null}
npm install @beyondwords/player
```

**2. Add a container element**

```html theme={null}
<div id="beyondwords-player"></div>
```

The container must exist in the DOM before you initialize the widget.

**3. Initialize the widget**

```javascript theme={null}
import BeyondWords from '@beyondwords/player';

new BeyondWords.Player({
  target: '#beyondwords-player',
  projectId: YOUR_PROJECT_ID,
  contentId: 'YOUR_CONTENT_ID',
});
```

Replace `YOUR_PROJECT_ID` and `'YOUR_CONTENT_ID'` with your project ID and content UUID.

## Load content

The widget needs `projectId` plus at least one identifier. If you pass multiple identifiers, the widget loads all matching published content as a playlist.

| Identifier | Use when |
| - | - |
| `contentId` | You have the BeyondWords content UUID |
| `sourceId` | You have your CMS article ID (recommended, because it's more stable than URLs) |
| `sourceUrl` | You want to match by page URL (defaults to `window.location.href` if nothing else is set) |
| `playlistId` | Loading a [Standard or Smart playlist](https://docs.beyondwords.io/docs-and-guides/audio/distribution/playlists.md) |
| `playlist` | Building a [dynamic playlist](https://docs.beyondwords.io/docs-and-guides/audio/distribution/playlists.md#create-a-dynamic-playlist) from an array of identifiers |

```javascript theme={null}
// Match by CMS source ID (recommended)
new BeyondWords.Player({
  target: '#beyondwords-player',
  projectId: YOUR_PROJECT_ID,
  sourceId: 'article-12345',
});

// Load a dashboard playlist
new BeyondWords.Player({
  target: '#beyondwords-player',
  projectId: YOUR_PROJECT_ID,
  playlistId: YOUR_PLAYLIST_ID,
});
```

## Configuration

### Dashboard settings

Configure the widget on the **Widget** page in your project dashboard:

* [**Widget settings**](https://docs.beyondwords.io/docs-and-guides/widget.md#widget-settings): General, audio, agent, appearance, and tracking settings. Your agent needs the Default version.
* [**Access tiers**](https://docs.beyondwords.io/docs-and-guides/access-tiers.md): Different experiences by audience.

### Property overrides

Pass properties in your embed code or NPM initialization to override dashboard settings. Values set at initialization take precedence over the API defaults. See [programmatic control](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/programmatic-control.md#how-overrides-work) for override order.

```html theme={null}
<script async defer
  src="https://proxy.beyondwords.io/npm/@beyondwords/player@latest/dist/umd.js"
  onload="new BeyondWords.Player({
    target: this,
    projectId: YOUR_PROJECT_ID,
    contentId: 'YOUR_CONTENT_ID',
    callToAction: 'Listen to this article',
    theme: 'dark',
  })">
</script>
```

Setting `playerStyle` to a legacy version (`standard`, `small`, or `large`) hides your agent.

## Programmatic control

The `new BeyondWords.Player(...)` call returns a widget instance you can control at runtime: play, pause, seek, change track, update properties, and listen to [events](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/events.md). See [programmatic control](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/programmatic-control.md) and the [Widget API](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/widget-api.md).

On single-page apps, call `player.destroy()` or `BeyondWords.Player.destroyAll()` when removing the widget to free browser resources. To keep one widget across routes instead, see [page navigation](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/page-navigation.md).

## FAQs

> [accordion] Should I use the embed script or NPM?
>
> Use the **embed script** for static sites, CMS templates, or quick prototypes. Use **NPM** when you're building with React, Vue, Next.js, or another framework where you import modules and manage component lifecycles.

> [accordion] Why isn't the widget loading?
>
> * Confirm the content has finished generating and is published in the project dashboard.
> * Check `projectId` and your content identifier are correct.
> * Ensure the `target` element exists before initialization (NPM).
> * Open the browser console for JavaScript errors.
> * If using `sourceUrl`, verify the page URL matches the content's `source_url`

> [accordion] Can I load multiple items in one widget?
>
> Yes. Pass multiple identifiers, a `playlistId`, or a `playlist` array. The widget loads all matching published content and plays them in sequence. See [playlists](https://docs.beyondwords.io/docs-and-guides/audio/distribution/playlists.md) for curated collections.

> [accordion] How do I build a custom player UI?
>
> Set `showUserInterface: false` to run in headless mode and build your own controls on top of the SDK. See [build your own UI](https://docs.beyondwords.io/docs-and-guides/widget/developer-guides/build-your-own-ui.md).

## GitHub repository

> [card] [JavaScript SDK repository](https://github.com/beyondwords-io/player)
>
> View the source code, releases, and API documentation on GitHub.


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