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

# Analytics integrations

Send audio analytics events to your chosen analytics platform.

If you're using the BeyondWords widget, events are sent to your project dashboard by default. You can also send events to Google Analytics or a custom analytics endpoint.

If you're using a custom player, you can send events to BeyondWords so they appear in your project dashboard.

> [accordion] Use the API
>
> Set up analytics integrations with the [BeyondWords API](https://docs.beyondwords.io/api-reference/overview.md):
>
> * [Get player settings](https://docs.beyondwords.io/api-reference/player-settings/show.md): `GET /projects/{project_id}/player_settings`
> * [Send analytics to Google Analytics or a custom endpoint](https://docs.beyondwords.io/api-reference/player-settings/update.md): `PUT /projects/{project_id}/player_settings`

## Send analytics to Google Analytics

1. Go to **Widget → Tracking → Integrations**.
2. Turn on **Google Analytics**.
3. Enter your Google Analytics Measurement ID or Google Tag Manager Container ID in the **Identifier** field.
4. Click **Save** or **Save all**.

## Send analytics to a custom endpoint

1. Go to **Widget → Tracking**.
2. Turn on **Custom endpoint**.
3. Enter the URL in **Endpoint URL**.
4. Click **Save** or **Save all**.

The BeyondWords widget will send analytics events to your endpoint as JSON `POST` requests using the [event schema](#event-schema) below.

## Send analytics to BeyondWords

To send analytics from a custom player to BeyondWords, send a `POST` request to `https://metrics.beyondwords.io` using the [event schema](#event-schema) below. We recommend sending as many fields as possible so events can be aggregated accurately, although sensible defaults will be applied for some missing fields.

Some fields may not apply to your implementation. These can be omitted and will be ignored.

When testing custom events, it may take up to an hour for data to appear in the BeyondWords dashboard. If you need help, [contact support](https://docs.beyondwords.io/docs-and-guides/support.md).

## Example event

The following example shows a typical analytics event payload. To inspect analytics events, search for `metrics.beyondwords.io` in your browser's Network tab.

```javascript Example event theme={null}
{
  "event_type": "play",
  "device_type": "desktop",
  "media_type": "content",
  "media_variant": "article",
  "access_tier": "anonymous",
  "project_id": 123,
  "content_id": "3f57001d-cb30-42c1-ad6f-047e813c360f",
  "source_id": "example-source-id",
  "analytics_id": 333,
  "ad_id": null,
  "media_id": 555,
  "media_format": "audio",
  "local_storage_id": "bef9218d-3871-450e-a7fa-5da65102f532",
  "listen_session_id": "839ff785-0cb8-4e74-a061-506f571c79ce",
  "session_created_at": 1672531200000,
  "duration": 123.45,
  "listen_length_seconds": 0.2,
  "listen_length_percent": 0.1620089105,
  "speed": 1,
  "segment_playback_enabled": true,
  "location": "https://example.com",
  "referrer": "https://example.com",
  "player_version": "1",
  "player_npm_version": "1.2.3"
}
```

## Event schema

**event\_type** `string`

The type of analytics event. There are four types:

* **load**: Content loaded successfully and the media's duration is known.
* **play**: The media started playing for the current content item.
* **play\_progress**: Playback reached the next 10% of the audio's duration.
* **ad\_link\_click**: The user clicked on the click-through URL for an ad.

**device\_type** `string`

The type of device that emitted the event. There are five types:

* **phone**: The width of the browser was between 0px and 499px.
* **tablet**: The width of the browser was between 500px and 999px.
* **desktop**: The width of the browser was 1000px or greater.
* **ios**: The event was sent from a native iOS app.
* **android**: The event was sent from a native Android app.

**media\_type** `string`

The type of media loaded in the widget. There are two types:

* **content**: The event was emitted during content playback.
* **ad**: The event was emitted during ad playback.

**media\_variant** `string`

The variant of media loaded in the widget. There are two types:

* **article**: The media is for the original article.
* **summary**: The media is for a summary of the article.

**access\_tier** `string`

The slug of the access tier applied to the widget. This field is omitted when the widget has no access tier.

**project\_id** `integer | null`

The numeric ID of the project whose content is loaded into the widget. This field might be null if content wasn't fetched from the API and is instead set manually in the widget.

**content\_id** `string | integer | null`

The string UUID or numeric ID of the content currently loaded into the widget. This field might be null if content wasn't fetched from the API and is instead set manually in the widget.

**source\_id** `string | null`

The string ID that can optionally be associated with the content currently loaded into the widget. This field might be null if the source\_id ID wasn't set in the BeyondWords API.

**analytics\_id** `integer | null`

A numeric ID used by BeyondWords for associating this event with your project. This field might be null if content wasn't fetched from the API and is instead set manually in the widget.

**ad\_id** `integer | null`

The numeric ID of the ad that is currently loaded into the widget. This field is null when an ad isn't playing, i.e., when content is playing.

**media\_id** `integer | null`

The numeric ID of the content or ad media field that is currently loaded into the widget. This field is null when VAST ads are playing.

**media\_format** `string`

The format of media loaded in the widget. There are two formats:

* **Audio**: The widget is playing audio (or will play audio).
* **Video**: The widget is playing video (or will play video).

**local\_storage\_id** `string | null`

A string UUID associated with the current user and stored in local storage under the 'beyondwords' key. This field is null if `analyticsConsent` is set to `without-local-storage` or `none`.

**listen\_session\_id** `string`

A string UUID associated with the current widget instance. This ID changes after the page is reloaded and is different for each widget instance.

**session\_created\_at** `integer`

The unix time in milliseconds at which the first analytics event was sent from the current widget instance, as reported by the user's browser.

**duration** `float`

The duration in seconds of the content or ad media currently loaded into the widget.

**listen\_length\_seconds** `float`

The duration in seconds that the user has listened to of the currently loaded media.

**listen\_length\_percent** `float`

The percentage that the user has listened to of the currently loaded media.

**speed** `float`

The speed at which the user is listening to the media, e.g., 0.5, 1, or 2.

**segment\_playback\_enabled** `boolean`

Whether playback from paragraphs is enabled, i.e., whether the `clickableSections` setting is anything other than "none".

**location** `string`

The value of window\.location.href when the event was emitted.

**referrer** `string`

The value of document.referrer when the event was emitted.

**player\_version** `string`

This will always be the string "1" but we may use this later, e.g., to run A/B tests.

**player\_npm\_version** `string`

The version of the NPM package as specified in the package.json file.

## FAQs

> [accordion] Why can't I send events to Google Analytics or a custom endpoint?
>
> Analytics integrations may not be included in your plan. They are currently available on Standard and Enterprise plans. You can upgrade in your BeyondWords dashboard, or [contact support](https://docs.beyondwords.io/docs-and-guides/support.md) for help.


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