Track YouTube video views and comments
Tracks views, likes, and comments for provided YouTube URLs in a Google Sheet with optional email notifications.
Last updated: August, 2019
YouTube makes it possible for anyone to create and share video content, and engage with viewers around the world. While the built-in analytics and notification options provided by YouTube are designed for a user's own channel, you may care deeply about content that extends beyond those bounds.
This solution uses the YouTube Data API to track performance of a user-curated list of public YouTube videos, including views, likes, and comments, in a Google Sheet. Additionally, email notifications can be enabled that send daily summaries of videos that have new comment activity so that you can engage with questions and comments shared for the video.
- Uses the YouTube advanced service to collect data on specific videos (such as number of views and comment data) via the YouTube Data API.
- Uses the Gmail Service to send notification emails when new video comments are detected.
- Creates an HTML template containing an Apps Script function to send custom notification emails.
- Make of copy of the spreadsheet here. It already contains the Apps Script code for the solution.
- Change the name of the sheet to the full email address where you’d like to receive email notifications.
- Locate URLs of videos you would like to track and add them in column A below cell A1. The URLs must be in format starting with "www.youtube.com/watch?v=."
YouTube Advanced Service setup
- From the spreadsheet, open the script editor by selecting Tools > Script editor.
- In the left-hand navigation pane, select + next to Services.
- Choose the YouTube Data API service, and click Add. Note: When using the template, you may find that this service has already been activated, in which case it will appear listed below Services in the left-hand navigation pane.
Test the code
- From the script editor, choose
markVideosfrom the drop-down box in the toolbar, then click the Run button (▶).
- When prompted, click the Review permissions button.
- Select your Google Workspace account from the list.
- Click the Allow button.
- When the script execution completes, you should see the details added in columns C through H, and you will receive an email for any videos that have more than zero comments. When running the function in the future, you will only receive an email with videos whose comment count has increased since the last time the script was run.
- Optionally, to turn off email notifications, change line 2 of
Apps Script trigger setup
Instead of running the script manually, set it up to run at regular intervals (such as once a day).
- From the script editor, navigate to the left-hand vertical toolbar, and click the Triggers icon.
- In the bottom right-hand corner, click the +Add Trigger button.
- Under Run, select the
- Under Select event source, choose Time-driven.
- Under Type, select Day timer.
- Select the desired time interval, such as 6am to 7am.
- Optionally, adjust the Failure notification settings to configure how and when you are contacted by email if your triggered function fails.
- Click Save.
To learn more about how it was built, check out this blog post.
You can also view the full source code of this solution on GitHub.
Were you able to get the solution up and running?
If you have an idea for another solution you'd like to see featured in our gallery submit a request on the GitHub issue tracker.