The YouTube Analytics API enables you to generate custom reports containing YouTube Analytics data. The API supports reports for channels and for content owners.
Arguments
- start_date
The start date for fetching YouTube Analytics data. The value should be in YYYY-MM-DD format.
- end_date
The end date for fetching YouTube Analytics data. The value should be in YYYY-MM-DD format.
- metrics
Character vector of YouTube Analytics metrics, such as views or likes,dislikes. See the documentation for channel reports or a list of the reports that you can retrieve and the metrics available in each report. The Metrics document contains definitions for all of the metrics.
- dimensions
Character vector of YouTube Analytics dimensions, such as video or ageGroup,gender. The Dimensions document contains definitions for all of the dimensions.
- filters
Character vector of filters that should be applied when retrieving YouTube Analytics data. The documentation for channel reports reports identifies the dimensions that can be used to filter each report, and the Dimensions document defines those dimensions.
Examples
if (FALSE) {
# auth
ryt_auth()
# get list of your videos
videos <- ryt_get_videos()
# function for loading video stat
get_videos_stat <- function(video_id) {
data <- ryt_get_analytics(
metrics = c('views', 'likes', 'dislikes', 'comments', 'shares'),
filters = stringr::str_glue('video=={video_id}')
)
if ( nrow(data) > 0 ) {
data <- mutate(data, video_id = video_id)
}
}
# load video stat
video_stat <- purrr::map_df(videos$id_video_id, get_videos_stat)
# join stat with video metadata
video_stat <- left_join(video_stat,
videos,
by = c("video_id" = "id_video_id")) %>%
select(video_id,
title,
day,
views,
likes,
dislikes,
comments,
shares)
}