title | description | labels | material_icon | create_time | update_time |
---|---|---|---|---|---|
Track YouTube video views and comments |
Tracks views, likes, and comments for provided YouTube URLs in a Google Sheet with optional email notifications. |
Apps Script, Sheets, Gmail, YouTube |
play_circle_filled_white |
2019-08-09 |
2019-08-12 |
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=."
- 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.
- From the script editor, choose
markVideos
from 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
code.gs
from'Y'
to'N'
.
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
markVideos
function. - 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.