JavaScript, webdev

YouTube Analytics Dashboard With Apps Script

player_apisThere are cases where you wish to collect statistics on your youtube videos or channel. There are few options to do it with YouTube API. As the YouTube’s API supports many languages you can choose the one that will work for your environment. In many of these options, you will need to develop a server side that will fetch the data and a front-end to present it and give the users option to query it. If you wish to dive deeper (e.g. specific metric on channel performance and videos statistics), you will need to work with YouTube Analytics API.

In this post, we will see a simple example to create a dashboard that will be updated on a daily basis. Since we wish to save ourselves from building (and maintaining!) a server side and a web app to access it, we will use the power of Google Apps Script (GAS) and Google sheets.

The Dashboard

Here you can find the “Dashboard example sheet”.
Feel free to copy it and work on your own version that is not in ‘read-only’ mode.

The first thing you will notice are the amazing colors.

Screenshot 2014-08-04 15.50.15

We have two main function in this dashboard

Screenshot 2014-08-04 15.50.36

One option is to extract the IDs from the links we provide in column D and the other goes and update all the stats on the active sheet. As a final step, we have a little dialog that give us the confirmation on this last update with errors (if we have some broken links in column D).


You can find the code for this example on a repository for Apps Scripts that I’ve created on GitHub. On the script over there you will also see a function that use the Analytic API (you must be the owner of the channel in order to run it). It gives much more power and many different metrics you can query on.

Another option is to follow the snippet below that drive this example

As a final step, we can create an automated task (e.g. cronjob) that will run our update function every night. This will make sure, we have an updated dashboard each time we open it.

YouTube Analytic API

If you wish to gain the full spectrum of metrics that YouTube API expose, you will need to use the Analytic API. Few metrics that you can fetch from this powerful API are:

  1. View metrics
  2. Watch time metrics
  3. Engagement metrics
  4. Playlist metrics
  5. Annotations metrics
  6. Audience retention metrics
  7. Earnings metrics
  8. Ad Performance metrics

Here is an example for an Apps Script that will fetch few metrics per video ID and will update your dashboard.

Happy hacking.

App script


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s