> For the complete documentation index, see [llms.txt](https://docs.cstplus.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cstplus.org/api-reference/general/analytics.md).

# Analytics

## Get viewer analytics

<mark style="color:blue;">`GET`</mark> `http://YOUR_SERVER:8080/api/analytics`

Returns viewer statistics for a given time range: watch time, concurrent viewers, traffic, and per-channel breakdown.

#### Query Parameters

| Name | Type   | Description                                                   |
| ---- | ------ | ------------------------------------------------------------- |
| from | string | Start of range as ISO 8601 timestamp. Defaults to 7 days ago. |
| to   | string | End of range as ISO 8601 timestamp. Defaults to now.          |

#### Headers

| Name                                            | Type   | Description                                       |
| ----------------------------------------------- | ------ | ------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer YOUR\_API\_KEY (requires `analytics:read`) |

{% tabs %}
{% tab title="200: OK " %}

```json
{
  "totalSessions": 1240,
  "totalWatchSec": 4320000,
  "totalBytes": 98000000000,
  "peakConcurrent": 87,
  "byChannel": [
    {
      "slug": "news",
      "name": "News 24",
      "sessions": 640,
      "watchSec": 2100000,
      "bytes": 51000000000
    }
  ],
  "byProtocol": {
    "hls": 1100,
    "ts": 140
  },
  "trafficSeries": [
    { "ts": "2026-06-25T00:00:00Z", "bytesPerSec": 12400000, "concurrent": 42 }
  ]
}
```

{% endtab %}
{% endtabs %}

***

### Export analytics as CSV

## Export analytics to CSV

<mark style="color:blue;">`GET`</mark> `http://YOUR_SERVER:8080/api/analytics/export.csv`

Returns a CSV file with per-session data for the requested time range. Each row is one viewer session.

#### Query Parameters

| Name | Type   | Description                          |
| ---- | ------ | ------------------------------------ |
| from | string | Start of range as ISO 8601 timestamp |
| to   | string | End of range as ISO 8601 timestamp   |

#### Headers

| Name                                            | Type   | Description                                       |
| ----------------------------------------------- | ------ | ------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer YOUR\_API\_KEY (requires `analytics:read`) |

{% tabs %}
{% tab title="200: OK CSV file download" %}

```
line_username,channel_slug,ip,country,protocol,started_at,watch_sec,bytes
john,news,1.2.3.4,FI,hls,2026-06-25T08:00:00Z,3600,52000000
```

{% endtab %}
{% endtabs %}

***

### Get ad metrics

## Get ad impression metrics

<mark style="color:blue;">`GET`</mark> `http://YOUR_SERVER:8080/api/analytics/ads`

Returns ad insertion metrics: impressions, fill rate, and viewer counts at impression time. Requires SSAI to be enabled on at least one channel.

Available on **Pro and Business** plans only.

#### Query Parameters

| Name    | Type   | Description                                                   |
| ------- | ------ | ------------------------------------------------------------- |
| from    | string | Start of range as ISO 8601 timestamp. Defaults to 7 days ago. |
| to      | string | End of range as ISO 8601 timestamp. Defaults to now.          |
| channel | string | Filter by channel slug. Omit to get data for all channels.    |

#### Headers

| Name                                            | Type   | Description                                       |
| ----------------------------------------------- | ------ | ------------------------------------------------- |
| Authorization<mark style="color:red;">\*</mark> | string | Bearer YOUR\_API\_KEY (requires `analytics:read`) |

{% tabs %}
{% tab title="200: OK " %}

```json
{
  "totalImpressions": 4820,
  "vastImpressions": 3100,
  "houseImpressions": 1720,
  "fillRate": 0.643,
  "byChannel": [
    {
      "slug": "news",
      "name": "News 24",
      "impressions": 2400,
      "vastImpressions": 1600,
      "houseImpressions": 800,
      "fillRate": 0.667,
      "avgViewers": 31
    }
  ],
  "series": [
    {
      "date": "2026-06-25",
      "impressions": 620,
      "fillRate": 0.71
    }
  ]
}
```

{% endtab %}

{% tab title="403: Forbidden Plan does not include ad metrics" %}

```json
{ "error": "plan_gate", "message": "Ad metrics require a Pro or Business plan" }
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
`fillRate` is calculated as `vastImpressions / totalImpressions`. A fill rate of 1.0 means every break got a paid ad. House ads fill the remaining breaks but do not count toward the paid fill rate.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.cstplus.org/api-reference/general/analytics.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
