This vignette demonstrates the enhanced features of tubern, showing you how to efficiently retrieve, analyze, and visualize YouTube Analytics data.
No more manual date calculations! Use intuitive relative dates:
# Get common date range options
get_common_date_ranges()
# Use relative dates in reports
report <- get_report(
ids = "channel==MINE",
metrics = "views,likes",
start_date = "last_30_days" # End date calculated automatically
)
# More examples
get_report(ids = "channel==MINE", metrics = "views", start_date = "this_month")
get_report(ids = "channel==MINE", metrics = "views", start_date = "last_quarter")
get_report(ids = "channel==MINE", metrics = "views", start_date = "yesterday")# Performance by device type - use get_report directly
device_performance <- get_report(
ids = "channel==MINE",
metrics = "views,estimatedMinutesWatched",
dimensions = "deviceType",
start_date = "last_30_days"
)
# Operating system breakdown
os_performance <- get_report(
ids = "channel==MINE",
metrics = "views,estimatedMinutesWatched",
dimensions = "operatingSystem",
start_date = "this_month"
)
# Both device and OS
device_os <- get_report(
ids = "channel==MINE",
metrics = "views,estimatedMinutesWatched",
dimensions = "deviceType,operatingSystem",
start_date = "last_7_days"
)tubern now provides helpful validation and suggestions:
# Invalid metrics get helpful suggestions
# get_report(ids = "channel==MINE", metrics = "vews", start_date = "last_7_days")
# Error: Invalid metric(s): vews
# Did you mean: 'vews' -> 'views'
# Check available metrics and dimensions
get_available_metrics()
get_available_metrics("view") # Filter by pattern
get_available_dimensions()
get_available_dimensions("country|city") # Geographic dimensions# Automatic plot creation (requires ggplot2)
daily_report <- get_daily_performance("last_30_days")
yt_quick_plot(daily_report) # Line plot over time
# Bar chart for top videos
top_videos <- get_top_videos("last_7_days")
yt_quick_plot(top_videos, chart_type = "bar")
# Custom x and y columns
geo_data <- get_geographic_performance("last_30_days")
yt_quick_plot(geo_data, x_col = "country", y_col = "views")# Set up authentication
yt_oauth("your-client-id", "your-client-secret")
# Get overview data
overview <- get_channel_overview("last_30_days")
overview_df <- yt_to_dataframe(overview)
# Get daily trends
daily <- get_daily_performance("last_30_days")
daily_df <- yt_to_dataframe(daily)
# Get top videos
top_videos <- get_top_videos("last_30_days", max_results = 10)
videos_df <- yt_to_dataframe(top_videos)
# Get geographic performance
geo <- get_geographic_performance("last_30_days")
geo_df <- yt_to_dataframe(geo)
# Create visualizations
yt_quick_plot(daily) # Daily trend
yt_quick_plot(top_videos) # Top videos
yt_quick_plot(geo) # Geographic performance
# Export data
yt_export_csv(overview, "channel_overview.csv")
yt_export_csv(daily, "daily_performance.csv")
yt_export_csv(top_videos, "top_videos.csv")# Demographic analysis
demographics <- get_audience_demographics("last_90_days")
demo_df <- yt_to_dataframe(demographics)
# Device analysis
devices <- get_report(
ids = "channel==MINE",
metrics = "views,estimatedMinutesWatched",
dimensions = "deviceType",
start_date = "last_90_days"
)
device_df <- yt_to_dataframe(devices)
# Geographic analysis
geography <- get_geographic_performance("last_90_days", max_results = 50)
geo_df <- yt_to_dataframe(geography)
# Combined analysis with dplyr (if available)
if (require(dplyr)) {
# Top countries by watch time
top_countries <- geo_df %>%
arrange(desc(estimated_minutes_watched)) %>%
head(10)
print(top_countries)
}# Analyze video performance over time
videos_monthly <- get_top_videos("this_month", max_results = 50)
videos_df <- yt_to_dataframe(videos_monthly)
# Compare with previous month
videos_prev <- get_top_videos("last_month", max_results = 50)
videos_prev_df <- yt_to_dataframe(videos_prev)
# Daily performance for trend analysis
daily_trends <- get_daily_performance(
"last_30_days",
metrics = c("views", "estimatedMinutesWatched", "likes", "comments")
)
trends_df <- yt_to_dataframe(daily_trends)
# Visualize trends
yt_quick_plot(daily_trends, x_col = "day", y_col = "views")scope = "monetary" only when you need revenue
datadiagnose_tubern() to troubleshoot authentication
issues"last_30_days",
"this_month"get_channel_overview()
before using get_report() directlymax_results parameter to limit data when
testingdiagnose_tubern() if you encounter
issuescheck_api_quota() to monitor your API usagesetup_guide = TRUE for first-time setup
helpyt_to_dataframe()yt_quick_plot() for rapid data explorationyt_export_csv() for external
analysisAuthentication Problems
API Quota Exceeded
Invalid Parameters