There 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.
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.
- Columns that must be ‘fixed’ are colored in orange. In this simple case, we only search for the youtube link in Column D:D. Our script knows how to handle both versions of links:
- Columns that we updating every night are colored in yellow.
We have two main function in this dashboard
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:
- View metrics
- Watch time metrics
- Engagement metrics
- Playlist metrics
- Annotations metrics
- Audience retention metrics
- Earnings metrics
- Ad Performance metrics
Here is an example for an Apps Script that will fetch few metrics per video ID and will update your dashboard.