Track YouTube video views and comments

Stay organized with collections Save and categorize content based on your preferences.

Coding level: Beginner
Duration: 20 minutes
Project type: Automation with a time-driven trigger

About this solution

This solution tracks the performance of public YouTube videos, including views, likes, and comments, in a Google Sheets spreadsheet. The trigger checks for updated information each day and sends an email if videos have new comment activity so that you can engage with questions and comments.

Screenshot of YouTube data in a Google Sheet

How it works

The script uses the advanced YouTube service to get YouTube video details and statistics for the video URLs listed in the Video Link column in each sheet. If the number of comments for a listed video has gone up, the script sends an email notification to the email address that the sheet is named after.

Apps Script services

This solution uses the following services:

Before you begin

To use this sample, you need the following prerequisites:

  • A Google Account (Google Workspace accounts might require administrator approval)
  • A web browser with access to the internet

Try it

Step 1: Set up the spreadsheet

  1. Click the button below to make a copy of the Track YouTube video views and comments spreadsheet.
    Make a copy
  2. Change the name of the Your_EmailL_Address sheet to your email address.
  3. Add the YouTube video URLs you want to track or use the provided URLs for testing.The URLs must start with the format www.youtube.com/watch?v=.

Step 2: Set up the YouTube advanced service

  1. Click Extensions > Apps Script. If YouTube is already listed under Services, you can skip to the next set of steps.
  2. Next to Services, click Add a service .
  3. From the list, select YouTube Data API and click Add.

Step 3: Add a trigger

  1. Click Triggers > Add trigger.
  2. For Choose which function to run, select markVideos.
  3. For Select event source, select Time-driven.
  4. For Select type of time based trigger, select Day timer.
  5. For Select time of day, choose your preferred time.
  6. When prompted, authorize the script.

Step 4: Test this solution

The trigger you set up runs the script once daily. You can run the script manually to test it.

  1. In the Apps Script project, click Editor .
  2. In the function dropdown, select markVideos.
  3. Click Run.
  4. Switch back to the spreadsheet to review the information the script added to the sheet.
  5. Open your email to review the email with the list of videos that have more than zero comments. When the script runs in the future, it only sends an email with videos whose comment count has increased since the last time the script ran.

Open the Apps Script project

The sample script's code includes in-line comments to help you understand how it works. To access the code, in the spreadsheet, click Extensions > Apps Script.

Contributors

This sample is maintained by Google with the help of Google Developer Experts.