This source code is used with Youtube Analitycs and will get information about my channel, like:
channel ID, start and end date , metric dimensions and sort by day using in one query.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | function getVideoEstimatedMinutesWatched(channelId) { const oneMonthInMillis = 1000 * 60 * 60 * 24 * 30; const today = new Date(); const lastMonth = new Date(today.getTime() - oneMonthInMillis); const metrics = [ 'views', 'estimatedMinutesWatched', 'averageViewDuration', 'subscribersGained' ]; const result = YouTubeAnalytics.Reports.query({ ids: 'channel==' + channelId, startDate: formatDateString(lastMonth), endDate: formatDateString(today), metrics: metrics.join(','), dimensions: 'day', sort: 'day' }); return result; } |
The result will be something like this:
1 | getVideoEstimatedMinutesWatched {"rows":[["2022-06-10",2,2,63,0],["2022-06-11",10,6,41,0],... |