Overview
TheAnalyticsOptimizationAgent analyzes video performance using YouTube Analytics API and generates actionable insights for optimization. It tracks views, retention, engagement, CTR, demographics, traffic sources, and provides comprehensive performance scoring.
Constructor
Database
required
Database instance for analytics history
Credentials
required
Credentials manager with YouTube Analytics API access
Properties
YouTubeAnalyticsAPI
YouTube Analytics API v2 client
YouTubeAPI
YouTube Data API v3 client
Map
Historical performance data cache
Logger
Logger instance for tracking analytics
Methods
initialize()
Initializes the agent and loads historical analytics data.Promise<boolean>
Returns true when initialization is complete
analyzeVideoPerformance(videoId)
Performs comprehensive analysis of video performance.string
required
YouTube video ID
Promise<Object>
Complete performance report
string
YouTube video ID
Object
Video metadata (title, description, tags, statistics)
Object
Analytics data (views, watch time, demographics, traffic, devices, engagement)
Object
Thumbnail performance (impressions, CTR, quality, recommendations)
Object
SEO performance (title score, description score, tag score, search performance)
Array<Object>
Actionable insights with recommendations
Object
Overall performance score with breakdown and grade
getVideoDetails(videoId)
Fetches video metadata from YouTube.string
required
YouTube video ID
Promise<Object>
Video details object
getVideoAnalytics(videoId)
Fetches comprehensive analytics for a video (last 30 days).string
required
YouTube video ID
Promise<Object>
Analytics data object
calculatePerformanceScore(analytics)
Calculates overall performance score (0-100).Object
required
Analytics data from getVideoAnalytics
Object
Performance score with breakdown and grade
analyzeThumbnailPerformance(videoId)
Analyzes thumbnail click-through rate.string
required
YouTube video ID
Promise<Object>
Thumbnail metrics with recommendations
analyzeSEOPerformance(videoDetails, analytics)
Analyzes SEO optimization quality.Object
required
Video details from getVideoDetails
Object
required
Analytics data from getVideoAnalytics
Promise<Object>
SEO metrics with scores and recommendations
generateInsights(videoDetails, analytics, thumbnailMetrics, seoMetrics)
Generates actionable insights from all metrics.Object
required
Video details
Object
required
Analytics data
Object
required
Thumbnail metrics
Object
required
SEO metrics
Promise<Array<Object>>
Array of insight objects
getRecentAnalytics(days)
Gets analytics summary for recent videos.number
default:"7"
Number of days to look back
Promise<Object>
Summary analytics for recent videos
Performance Scoring
The agent uses a weighted scoring system:Insight Types and Triggers
Views Insights
Views Insights
- Success: more than 10,000 views
- Warning: less than 1,000 views (recommend promotion/SEO optimization)
Retention Insights
Retention Insights
- Success: more than 50% average view percentage
- Critical: less than 30% average view percentage (review structure/pacing)
Thumbnail Insights
Thumbnail Insights
- Success: more than 8% CTR
- Warning: less than 3% CTR (recommend A/B testing)
SEO Insights
SEO Insights
- Success: more than 80 SEO score
- Warning: less than 50 SEO score (optimize title/description/tags)
Engagement Insights
Engagement Insights
- Success: more than 5% engagement rate
- Warning: less than 1% engagement rate (encourage interaction)
Usage Example
Analytics Metrics
Views Metrics
Views Metrics
- Total views
- Total impressions
- Average CTR (Click-Through Rate)
- Daily view data
Watch Time Metrics
Watch Time Metrics
- Total minutes watched
- Average view duration
- Average view percentage (retention)
- Retention quality assessment
Engagement Metrics
Engagement Metrics
- Engagement rate: (likes + comments) / views
- Like ratio: likes / (likes + dislikes)
- Comments per view
- Engagement quality assessment
Demographics
Demographics
- Age group distribution
- Gender distribution
- Primary audience identification
Traffic Sources
Traffic Sources
- Source breakdown (search, suggested, external, etc.)
- Top traffic source
- Organic percentage (search + suggested)
Devices
Devices
- Device type distribution (mobile, desktop, tablet, TV)
- Mobile percentage
Best Practices
Analyze Regularly
Analyze Regularly
Run analysis 3-7 days after publishing to get meaningful data. Re-analyze at 30 days for long-term performance.
Act on Critical Insights
Act on Critical Insights
Prioritize ‘critical’ insights with ‘high’ impact. These indicate significant issues affecting video performance.
Track Performance Over Time
Track Performance Over Time
Use getRecentAnalytics() weekly to identify trends and patterns in your content performance.
Focus on Retention
Focus on Retention
Retention (average view percentage) is one of the most important metrics. Target >50% for good performance.
Optimize Based on Data
Optimize Based on Data
Use SEO scores and thumbnail CTR to guide optimization efforts. Apply learnings to future videos.
YouTube Analytics API Requirements
OAuth 2.0 Credentials
OAuth 2.0 Credentials
Requires OAuth 2.0 with scope: https://www.googleapis.com/auth/youtube.readonly and https://www.googleapis.com/auth/yt-analytics.readonly
Data Delay
Data Delay
YouTube Analytics data has a 24-48 hour delay. Recent videos may show incomplete data.
Historical Data
Historical Data
The agent queries last 30 days by default. Adjust date ranges in method calls for different periods.