This is the legacy documentation for Google Ads scripts. Go to the current docs.

YouTube Analytics

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

Create report for a channel

function runYoutubeAnalyticsReport() {
  // Get the list of all channels.
  var myChannels = YouTube.Channels.list('id', {mine: true});

  // Pick the first available channel.
  var channel = myChannels.items[0];
  var channelId =;

  // Set the dates for report.
  var today = new Date();
  var oneMonthAgo = new Date();
  oneMonthAgo.setMonth(today.getMonth() - 1);

  var todayFormatted = Utilities.formatDate(today, 'UTC', 'yyyy-MM-dd');
  var oneMonthAgoFormatted = Utilities.formatDate(oneMonthAgo, 'UTC',

  // See for
  // supported dimensions and metrics.
  var analyticsResponse = YouTubeAnalytics.Reports.query(
    'channel==' + channelId,
      dimensions: 'day',
      sort: '-day'