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.


Technology highlights

  • 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.

Try it

Learn more about this solution

Spreadsheet setup

  1. Make of copy of the spreadsheet here. It already contains the Apps Script code for the solution.
  2. Change the name of the sheet to the full email address where you’d like to receive email notifications.
  3. 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 ""

YouTube Advanced Service setup

  1. From the spreadsheet, open the script editor by selecting Tools > Script editor.
  2. In the left-hand navigation pane, select + next to Services.
  3. 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

  1. From the script editor, choose markVideos from the drop-down box in the toolbar, then click the Run button (▶).
  2. When prompted, click the Review permissions button.
  3. Select your Google Workspace account from the list.
  4. Click the Allow button.
  5. 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.
  6. Optionally, to turn off email notifications, change line 2 of from 'Y' to 'N'.

Apps Script trigger setup

Instead of running the script manually, set it up to run at regular intervals (such as once a day).

  1. From the script editor, navigate to the left-hand vertical toolbar, and click the Triggers icon.
  2. In the bottom right-hand corner, click the +Add Trigger button.
  3. Under Run, select the markVideos function.
  4. Under Select event source, choose Time-driven.
  5. Under Type, select Day timer.
  6. Select the desired time interval, such as 6am to 7am.
  7. Optionally, adjust the Failure notification settings to configure how and when you are contacted by email if your triggered function fails.
  8. Click Save.

Next steps

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.