[object Object] Icon

Learn how to create, start, manage and modify Encodings

[object Object] Icon

Learn how to create, start, manage and modify Players

[object Object] Icon

Learn how to create, start, manage and modify Analyticss

Docs Home
User shortcuts for search
Focus by pressing f
Hide results by pressing Esc
Navigate via   keys

Wed Feb 12 2020

Getting started with the Analytics API

OverviewLink Icon

The Bitmovin Analytics API lets us query for usage data of our videos. We can filter, aggregate and group data in the API request already, so we’re able to fetch precisely the data we need. In this section you’ll learn how to analyze the performance of your video platform and how to learn more about people watching your videos.

InstallationLink Icon

To get started, we need the Bitmovin API client. We’ll use the JavaScript client in all examples, but there are clients for several other languages as well. If you haven’t already, install the Bitmovin client:

1npm install bitmovin-javascript

Let’s create an analytics query builder in your Javascript application:

1import Bitmovin from 'bitmovin-javascript';
3const bitmovin = new Bitmovin({ apiKey: '<YOUR API KEY>' });
4const queryBuilder = bitmovin.analytics.queries.builder;
6const fromDate = new Date();
9const toDate = new Date();

Your first QueryLink Icon

The query builder provides us with a nice query interface. We always have to pass the time period we’re interested in. Here we use the first two weeks of the current month, but feel free to specify your own fromDate and toDate. Please just keep in mind that your data is only retained for 90 days.

We’ll use the queryBuilder, fromDate and toDate in most examples of this guide, so make sure they’re available in your code.

Let’s try running a query for the total number of video impressions:

2 .count('IMPRESSION_ID')
3 .between(fromDate, toDate)
4 .query()
5 .then(console.log);

If everything worked out, the number of video impressions in the given interval is printed to your console.

As you’ll learn in the following sections, the queryBuilder offers you several methods to filter, aggregate, group, sort and limit your data.

After you’ve composed your query, you call the query() method which submits the API request and returns a promise. This promise resolves when the API request finishes. In our case we want to log the result to the console, so we pass console.log as callback function to the then() method of the promise.

Give us feedback