Skip to main content

Overview

The AnalyticsOptimizationAgent 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

  • Success: more than 10,000 views
  • Warning: less than 1,000 views (recommend promotion/SEO optimization)
  • Success: more than 50% average view percentage
  • Critical: less than 30% average view percentage (review structure/pacing)
  • Success: more than 8% CTR
  • Warning: less than 3% CTR (recommend A/B testing)
  • Success: more than 80 SEO score
  • Warning: less than 50 SEO score (optimize title/description/tags)
  • Success: more than 5% engagement rate
  • Warning: less than 1% engagement rate (encourage interaction)

Usage Example

Analytics Metrics

  • Total views
  • Total impressions
  • Average CTR (Click-Through Rate)
  • Daily view data
  • Total minutes watched
  • Average view duration
  • Average view percentage (retention)
  • Retention quality assessment
  • Engagement rate: (likes + comments) / views
  • Like ratio: likes / (likes + dislikes)
  • Comments per view
  • Engagement quality assessment
  • Age group distribution
  • Gender distribution
  • Primary audience identification
  • Source breakdown (search, suggested, external, etc.)
  • Top traffic source
  • Organic percentage (search + suggested)
  • Device type distribution (mobile, desktop, tablet, TV)
  • Mobile percentage

Best Practices

Run analysis 3-7 days after publishing to get meaningful data. Re-analyze at 30 days for long-term performance.
Prioritize ‘critical’ insights with ‘high’ impact. These indicate significant issues affecting video performance.
Use getRecentAnalytics() weekly to identify trends and patterns in your content performance.
Retention (average view percentage) is one of the most important metrics. Target >50% for good performance.
Use SEO scores and thumbnail CTR to guide optimization efforts. Apply learnings to future videos.

YouTube Analytics API Requirements

YouTube Analytics data has a 24-48 hour delay. Recent videos may show incomplete data.
The agent queries last 30 days by default. Adjust date ranges in method calls for different periods.