I'm looking to create a piece of software that sends requests to YouTube's server on behalf of the user and organizes the watch time data nicely into charts
So far, I have come up with the following:
async function getYouTubeAnalyticsData(result: GoogleTokensResult) { // https://developers.google.com/youtube/analytics/content_owner_reports const params = { dimensions: "day", startDate: "2023-07-01", endDate: "2023-08-02", ids: "channel==MINE", // https://developers.google.com/youtube/analytics/metrics metrics: "views,estimatedMinutesWatched,averageViewDuration,averageViewPercentage" }; const searchParams = new URLSearchParams(params); // https://developers.google.com/youtube/analytics/reference/reports/query const response = await fetch(`https://youtubeanalytics.googleapis.com/v2/reports?${searchParams}`, { headers: { Authorization: `Bearer ${result.access_token}` } }); return response.json();}
The problem is that I only get a basic report
In this case, the output shape returned by getYouTubeAnalyticsData
is:
{"columnHeaders": [ {"name": "day", "columnType": "DIMENSION", "dataType": "STRING"}, {"name": "channel", "columnType": "DIMENSION", "dataType": "STRING"}, {"name": "views", "columnType": "METRIC", "dataType": "INTEGER"}, {"name": "estimatedMinutesWatched", "columnType": "METRIC", "dataType": "INTEGER"}, {"name": "averageViewDuration", "columnType": "METRIC", "dataType": "INTEGER"}, {"name": "averageViewPercentage", "columnType": "METRIC", "dataType": "FLOAT"}, ],"kind": "youtubeAnalytics#resultTable","rows": [ ["2023-07-01", "CHANNEL_ID", 27, 39, 87, 11.95], [...] ]}
Instead, I'm looking to get much deeper data, for example:
- In day 1, the user watched 100s in channel A and 200s in channel B
- In day 2, the user watched 300s in channel C and 400s in channel D