Player Management API Sample: Using last_viewed Data

Product(s)
Video Cloud
Brightcove Player
Role(s)
API Developer
Topic(s)
Analytics
API(s)
Player Management API
Type
Support Doc

In this topic, you will learn about reports using the player's last_viewed data.

Disclaimer

Understanding last_viewed information

Each player has associated with it an array that contains a record of how many times a player was loaded. This information is stored in an array name last_viewed. You see below an example of such an array. Note that the count records how many time in the day the specific player was loaded. The date specifies the specific day.

[
  {
    "count": 13,
    "date": "2018-10-24T05:00:00.000Z"
  }, {
    "count": 22,
    "date": "2018-10-23T05:00:00.000Z"
  }, {
    "count": 40,
    "date": "2018-10-22T05:00:00.000Z"
  }, {
    "count": 2,
    "date": "2018-10-21T05:00:00.000Z"
  }
]

App architecture

The high-level application logic for this app is as follows:

  1. Gather user data necessary to retrieve information for all players in an account
  2. Build the JSON data structure to pass to the API for player creation
  3. On button click, perform AJAX call to retrieve information for all players in an account
  4. On AJAX call success, extract the last_viewed array for each player.
  5. For each player, display the last_viewed information in the table

Sample app

Find all the code associated with this sample in this GitHub repository.

Notes on the app:

  • If you do not enter data, a Brightcove Learning Services account is used for demonstration purposed.
  • To see the table at a more readable width, click the EDIT ON CODEPEN link.
  • The raw players data is displayed under the table in a textbox, if you are interested in viewing that.

See the Pen Gather Player last_viewed Statistics by Brightcove Learning Services (@rcrooks1969) on CodePen.

Using the CodePen

Here are some tips to effectively use the above CodePen:

  • Toggle the actual display of the player by clicking the Result button.
  • Click the HTML/CSS/JS buttons to display ONE of the code types.
  • Click Edit on CodePen in the upper right corner to fork this CodePen into your own account.
  • Find all the code associated with this sample in this GitHub repository.

Proxy code

In order to build your own version the sample app on this page, you must create and host your own proxy. (The proxies used by Brightcove Learning Services only accept requests from Brightcove domains.) A sample proxy, very similar to the one we use, but without the checks that block requests from non-Brightcove domains, can be found in this GitHub respository. You will also find basic instructions for using it there, and a more elaborate guide to building apps around the proxy in Using the REST APIs.