Connect YouTube Analytics to Google Sheets With Apps Script
On this page, 10 sections
To connect YouTube Analytics to Google Sheets, write a short Apps Script that calls the YouTube Analytics API and pastes the rows into a sheet, then put it on a time trigger. Google documents exactly this pattern in its Apps Script reference, with a sample that writes daily views, watch time and new subscribers for a channel.
One thing to settle first: there are two different APIs. The YouTube Data API returns what a video is: title, description, tags. The YouTube Analytics API returns how it performed: views, watch time, subscribers gained.
If your sheet has titles and you wanted daily performance reports, you used the wrong one. I read Google’s pages for both on 11 October 2026 and this post follows what they say.
I did not run the script below against a live channel for this post. It is Google’s sample, lightly extended, and I mark the places where it differs so you know which lines are mine.
Which API gives you which data
Both APIs live under the same Google Cloud project, and both are reachable from Apps Script, but they answer different questions.
- Data API (v3). Metadata about videos, playlists, channels and comments. Used by most of the YouTube-to-Sheets guides you will find, including the video details walkthrough on this site.
- Analytics API (v2). Reports with metrics and dimensions, such as
viewsbyday.
The Analytics API reference lists the authorisation scopes it accepts. yt-analytics.readonly covers activity metrics like views. yt-analytics-monetary.readonly is the separate scope for estimated revenue and ad performance. The same page carries a notice that requests to the query method now also require the youtube.readonly scope.
That last line is easy to miss. If a copied older script fails with an authorisation error, check its scopes against this list first.
What you need before you write anything
- Be able to sign in with the Google account that owns or manages the channel. Analytics data is private to the channel, so sign in as an account that can access it.
- Open a Google Sheet, then go to Extensions, Apps Script.
- In the Apps Script editor, add the two advanced services: YouTube Analytics API and YouTube Data API. Google’s page says the Analytics service is an advanced service that must be enabled before use.
- Save. The first run will ask you to approve the scopes.
You do not need to write an OAuth flow. Apps Script handles it, which is the main reason to use it over a Python script for a sheet-sized job.
The script
This is the shape of Google’s own sample. It looks up the channel you are signed in as, asks for four metrics by day for the last 30 days, and writes a header row plus the data.
function pullChannelAnalytics() {
const channels = YouTube.Channels.list('id,contentDetails', { mine: true });
const channelId = channels.items[0].id;
const end = new Date();
const start = new Date(end.getTime() - 30 * 24 * 60 * 60 * 1000);
const fmt = d => Utilities.formatDate(d, Session.getScriptTimeZone(), 'yyyy-MM-dd');
const result = YouTubeAnalytics.Reports.query({
ids: 'channel==' + channelId,
startDate: fmt(start),
endDate: fmt(end),
metrics: 'views,estimatedMinutesWatched,averageViewDuration,subscribersGained',
dimensions: 'day',
sort: 'day'
});
if (!result.rows) { console.log('No rows returned.'); return; }
// Mine: write into a named tab instead of creating a new spreadsheet each run
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName('YT Analytics') || ss.insertSheet('YT Analytics');
sheet.clear();
sheet.appendRow(result.columnHeaders.map(h => h.name));
sheet.getRange(2, 1, result.rows.length, result.columnHeaders.length)
.setValues(result.rows);
}
Two changes from Google’s sample. Google’s version calls SpreadsheetApp.create() and makes a new file every time it runs, which is the wrong behaviour for something you will schedule. Mine writes to one tab and clears it first. And I kept the column names as the API returns them, so you can match them against the reference without a translation step.
Changing the report
The metrics string and the dimensions string are the whole report. Swap day for another dimension and you get a different shape, but not every combination is allowed. Google’s channel reports page lists which metrics can go with which dimensions, and the API returns an error for a combination it does not support. Check that page before you invent a combination.
If you want revenue, you need the monetary scope, and the channel must be monetised. For a channel that is not, expect an error and not a column of zeros.
When the script fails
Three failures to check first.
- An authorisation error on the first run. Re-run and approve every scope in the prompt. If you added a service after authorising, Apps Script asks again.
- The service is not defined.
YouTubeAnalytics is not definedmeans the advanced service was not added in the editor sidebar. The code alone is not enough. result.rowsis undefined. The query worked and there was nothing to return for that range. The sample handles this by logging and returning, and so does the version above.
A fourth cause is signing in with a Google account that is not attached to the channel. The query uses the channel of whoever is signed in, so it silently asks about the wrong channel.
Run it on a schedule
A report you have to run by hand is a report you will stop running. In the Apps Script editor, open Triggers, add a trigger for pullChannelAnalytics, choose a time-driven source and a daily timer.
Two Apps Script limits matter here, both from Google’s quotas page, which I read on 11 October 2026 (last updated 3 September 2026).
- A single execution can run for 6 minutes, on consumer and Workspace accounts alike.
- Total trigger runtime per day is 90 minutes on a consumer account and 6 hours (360 minutes) on Google Workspace.
A 30-day daily report is one API call, so the 90 minute daily budget only matters if you loop over many videos or many channels. If you do, read the quota explainer for the Data API before you start, because that has its own daily ceiling.
If you only need the list of videos with titles and links, this older walkthrough for pulling every channel video link into a sheet covers that without the Analytics API.
Why numbers differ from YouTube Studio
Expect small differences, and treat them as a reason to check, not to panic.
- Date range edges. The API takes
startDateandendDateas calendar dates. Studio’s range selector can be in a different time zone to your script. Apps Script usesSession.getScriptTimeZone()in the sample, which is the script’s setting, not necessarily your channel’s. - Recent days are incomplete. Google’s Analytics API data model page says the underlying data is not real-time and that processing typically adds a latency of 48 to 72 hours. If yesterday looks low or missing, re-pull it in a few days.
- Different units.
estimatedMinutesWatchedis minutes, as the name says. Check the unit on the Studio side before you compare two numbers.
The same page adds that the response only includes data up to the last day for which every metric in your query is available.
It also says the Analytics API will not match real-time Studio numbers, and that for current view, like or comment counts on a video you should use the Data API’s videos.list instead. I read that page on 11 October 2026 (last updated 14 September 2026).
Keep history instead of overwriting
The script above clears the tab on every run. That is fine for a dashboard that always shows the last 30 days. It is wrong if you want a record, because once the tab is cleared, the numbers you pulled last week are gone.
For history, do not call sheet.clear(). Read the existing date column, and append only the dates that are not already there.
Because the newest days are still processing (48 to 72 hours, per Google, plus the current day), overwrite the last 4 days on each run and append the rest. I have not tested how far back numbers move after that, so compare your sheet with Studio for a week and see which days change.
A second tab is cheaper than clever code. Let one tab hold the raw pull, and build charts and pivot tables on a second tab that references it. When you change the metrics in the script, the chart tab keeps working as long as the column order stays the same.
The reason to bother is the question the data answers. A channel owner usually wants to know whether views moved after a change, such as a new title format or a different upload day. Only a stored series can answer that. A rolling 30-day window forgets the answer as it scrolls past.
Keep the metric list short. The sample asks for four metrics and returns one row per day. Every extra metric is another column to check against Studio, and the reference page restricts which metrics can be combined. Start with views and watch time, confirm they match, and add one metric at a time.
Questions people ask
Can I connect YouTube Analytics to Google Sheets without code?
I only checked Google’s developer documentation, which describes the Apps Script route. I did not test third-party connectors, so I cannot say how they work or what they cost.
Can I import data for a channel I do not own?
Not Analytics. The report is private to the channel, and the sample queries channel== with the signed-in user’s own channel ID. Public numbers like view counts come from the Data API instead.
Does this use my YouTube Data API quota?
The sample also calls YouTube.Channels.list, a Data API method that costs 1 unit per call on Google’s quota table. That is negligible. I did not find the Analytics API’s own quota in the pages I read, so check the Cloud console for it.
Do this today
Create a sheet, enable the two advanced services, paste the script, run it once and approve the scopes. Then add the daily trigger. Then you have a report that refreshes itself.
Resources
- YouTube Analytics service, Apps Script, read 11 October 2026
- YouTube Analytics API, Reports: query, read 11 October 2026
- YouTube Analytics API channel reports, read 11 October 2026
- YouTube Analytics API data model, data freshness and latency, read 11 October 2026
- Apps Script quotas, read 11 October 2026
- YouTube Data API quota costs, read 11 October 2026