Tutorials

Read the statistics of your videos and live streams with the video analytics API

How your own code can read video and live stream statistics through the DCAST API: stream status and peak viewers, account periods, rankings and paging.

dcast Team
7 min read
Share:
laptop, workstaion, office, work, business, computer, writing, working, desk, notebook, blog, notepad, table, coffee, company
On this page

If you build reports, dashboards or a client portal, you probably want your video and live stream numbers in your own code instead of copied by hand. The DCAST video analytics API lets your code read how your videos and live broadcasts perform, with the same peak viewer count that your dashboard shows. This article walks through what you can read, how to interpret each answer, and which checks to run so that the numbers you publish are the numbers you meant to publish.

Upload, stream and sell your videos. Start on the free plan — no card needed.

Get Started Free

What the video analytics API gives you

The analytics reads cover several levels. You can ask for an account summary, a ranking of your videos, a ranking of your live broadcasts, the analytics of one broadcast, the detail of one video, and a geography read. There are also summary and statistics reads that sit next to them. You pick the level that matches the question you are answering, and you do not need to stitch everything together from one big response.

Two ideas run through all of them. First, the answers describe your account only, so what you read is your own library and your own broadcasts. Second, the answers try to be honest about what they covered: they name the period that was applied and they say whether a ranking is complete. The sections below take these in turn, because most reporting mistakes come from ignoring exactly those two signals.

Read stream analytics and the peak viewer count

The stream analytics give each broadcast of your account a status, live or offline, just as every other stream read of the API does. That means you can use one status vocabulary across your whole integration. A broadcast that your encoder is feeding reads as live, and one that is not reads as offline, so your report does not need its own rule for deciding what counts as on air.

The peak viewer count follows a simple rule. While a broadcast is on air, its peak is never lower than the number of people watching it right now. After the broadcast goes off air, the analytics keep the peak that was stored for it. The same behaviour applies both to the list of your broadcasts and to the analytics of a single broadcast, so you do not get a different number depending on which read you chose.

There is a practical consequence for timing. If you want the peak to include the audience watching at that moment, read the stream analytics while the broadcast is on air. If you read it after the broadcast ends, you get the stored peak, which is the right number for a post-event report. Decide which of the two you are producing before you schedule your job, and label the report accordingly.

Your dashboard and the API take the peak from one shared rule. A report built from the API therefore matches the peak you see in the dashboard. If a stakeholder compares your automated report with the dashboard and the figures differ, you can rule out two different peak definitions and look at timing or period instead.

Choose the period for the account summary

The account analytics read covers the last thirty days unless you ask for another period. You can ask for a shorter or longer window, for example a week or ninety days, and the answer tells you the window that it applied. Always read that field back instead of assuming your request was honoured, and store it next to the figures in your own database.

Why does this matter? Imagine a script with a typo in the period. A careless service would echo your typo back and leave you thinking you had a custom window. Here a mistyped value comes back as the default window, so the applied period in the answer will not match what you intended. A one-line check in your code that compares the requested period with the applied one turns a silent mistake into a visible error.

The rankings behave differently when the period is wrong. For the video ranking and the broadcast ranking, the accepted periods are seven days, thirty days, ninety days or all, and any other value is refused with a bad request answer that names the field. That is stricter than the account summary, so handle both behaviours in your client: expect a default window from one and a refusal from the other.

The analytics of a single broadcast takes the same four period values. When you give no period, it uses the value all, so a single-broadcast read without a period covers the widest window. Pass a period explicitly whenever you compare broadcasts with each other, so that each one is measured over the same span.

Understand rankings and the truncated answer

The rankings of your videos and of your broadcasts say whether they cover your whole catalogue or only part of it. When a very large catalogue is ranked only in part, the answer says so and gives the real size of your catalogue next to it. In that case the ranking is built from your newest videos or broadcasts, so you know which part was counted.

For a smaller catalogue, the answer marks the ranking as complete and reports the exact number of items in it. This is the case you will see most often while your library is modest. It also gives you a clean test for your own code: if the answer says it is not truncated, the total it reports is the real count, and you can show the ranking as it is.

When the answer is truncated, do not present the ranking as a ranking of everything you own. Say in your report that it covers your newest items, and show the catalogue size that the answer gives you so readers see how much was left out. An older video that performs well may not appear at all, and a truthful label protects you from a client asking why a known favourite is missing.

Page through your video list by offset

Reports often start from the video list and then fetch detail for each item. When your code pages through your video list by offset, the answer reports the page that matches the rows it returned. You can rely on that page value as a cross-check: if you asked for a given offset and the reported page is not the one you expected, stop and investigate before you merge the rows into your dataset.

Keep the key on your server and check before you publish

Keep the API key on your server and fetch the numbers from there, not from a page that your visitors load. Anyone who can open your page can read what the page loads, so a key placed there is a key you have handed out. Let your server fetch the figures on a schedule or on demand, store them, and serve only the numbers to your visitors.

Before you publish a report, run a short checklist. Compare the peak of one finished broadcast with your dashboard, since both use one shared rule. Compare the period you asked for with the period the answer applied. Look at whether each ranking says it was truncated, and carry that wording into your output. Finally, confirm that your paging offsets and the reported page agree. Four checks like these cost little and catch most of the problems that make a number untrustworthy.

Beyond the product, decide what each number is for. A live peak is a good headline for an event, but it says little about how a video performs over months, so choose the period that fits the decision you want to support. Write the period and the date you read the numbers on every chart, keep the raw answers, and you will be able to explain any figure that someone questions later.

API documentation for this topic

d

dcast Team

Professional video streaming experts helping creators succeed.

Start Your Video Business Today

Upload, stream and sell your videos. Start on the free plan — no card needed.

Get Started Free