--- name: seo-analytics description: Generate visual SEO analysis reports using Google PageSpeed Insights API. Use when user asks to analyze website performance, SEO scores, Core Web Vitals, or page speed. Outputs an interactive HTML report with charts and actionable recommendations. --- # SEO Analytics Skill Generate comprehensive SEO and performance analysis reports for any website using Google PageSpeed Insights API. ## When to Use - "Analyze the SEO of https://example.com" - "Check the performance of my website" - "Generate a Core Web Vitals report for..." - "What's the page speed score of..." - "SEO audit for..." ## API Key Requirement **IMPORTANT**: This skill requires a Google PageSpeed Insights API key. If the user has not provided an API key, you MUST ask for one before proceeding. ### When No API Key is Provided If the user requests SEO analysis without providing an API key, respond with: --- **To run SEO analysis, I need a Google PageSpeed Insights API key.** **How to get your API key (takes ~2 minutes):** 1. Go to [Google Cloud Console](https://console.cloud.google.com/) 2. Create a new project or select an existing one 3. Navigate to **APIs & Services** > **Library** 4. Search for "**PageSpeed Insights API**" and click **Enable** 5. Go to **APIs & Services** > **Credentials** 6. Click **Create Credentials** > **API Key** 7. Copy your new API key Once you have the key, provide it and I'll run the analysis. --- ### API Key Usage The API key can be provided in two ways: 1. As a command line argument: `npx ts-node analyze.ts ` 2. As an environment variable: `PAGESPEED_API_KEY` ## Quick Start ``` User: "Analyze https://eng0.ai" # If no API key provided, ask user for one first # With API key: Output: - ./seo-report.html (interactive report with charts) - Console summary with key metrics ``` ## How to Execute ### Step 1: Run the Analysis Script ```bash npx ts-node analyze.ts https://example.com YOUR_API_KEY ``` Or with environment variable: ```bash PAGESPEED_API_KEY=your_key npx ts-node analyze.ts https://example.com ``` ### Step 2: Inline Execution (Alternative) Create and run `analyze.ts` in the current directory: ```typescript // analyze.ts - SEO Analysis Script const url = process.argv[2]; const apiKey = process.argv[3] || process.env.PAGESPEED_API_KEY; if (!url) { console.error('Usage: npx ts-node analyze.ts [API_KEY]'); console.error('Or set PAGESPEED_API_KEY environment variable'); process.exit(1); } interface AuditResult { title?: string; description?: string; score?: number | null; displayValue?: string; numericValue?: number; } interface PageSpeedResult { lighthouseResult: { categories: { performance: { score: number }; accessibility: { score: number }; 'best-practices': { score: number }; seo: { score: number }; }; audits: { [key: string]: AuditResult; }; }; } async function analyzeUrl(targetUrl: string, strategy: 'mobile' | 'desktop'): Promise { let apiUrl = `https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=${encodeURIComponent(targetUrl)}&strategy=${strategy}&category=performance&category=accessibility&category=best-practices&category=seo`; if (apiKey) { apiUrl += `&key=${apiKey}`; } console.log(`Analyzing ${strategy}...`); const response = await fetch(apiUrl); if (!response.ok) { throw new Error(`API error: ${response.status} ${response.statusText}`); } return response.json() as Promise; } function getScoreColor(score: number): string { if (score >= 90) return '#0cce6b'; if (score >= 50) return '#ffa400'; return '#ff4e42'; } function generateReport(mobile: PageSpeedResult, desktop: PageSpeedResult, targetUrl: string): string { const m = mobile.lighthouseResult; const d = desktop.lighthouseResult; const mobileScores = { performance: Math.round(m.categories.performance.score * 100), accessibility: Math.round(m.categories.accessibility.score * 100), bestPractices: Math.round(m.categories['best-practices'].score * 100), seo: Math.round(m.categories.seo.score * 100), }; const desktopScores = { performance: Math.round(d.categories.performance.score * 100), accessibility: Math.round(d.categories.accessibility.score * 100), bestPractices: Math.round(d.categories['best-practices'].score * 100), seo: Math.round(d.categories.seo.score * 100), }; const webVitals = { mobile: { lcp: m.audits['largest-contentful-paint'], tbt: m.audits['total-blocking-time'], cls: m.audits['cumulative-layout-shift'], fcp: m.audits['first-contentful-paint'], si: m.audits['speed-index'], tti: m.audits['interactive'], }, desktop: { lcp: d.audits['largest-contentful-paint'], tbt: d.audits['total-blocking-time'], cls: d.audits['cumulative-layout-shift'], fcp: d.audits['first-contentful-paint'], si: d.audits['speed-index'], tti: d.audits['interactive'], }, }; // Extract top opportunities const opportunities: string[] = []; for (const [key, audit] of Object.entries(m.audits)) { if (audit.score !== undefined && audit.score < 0.9 && audit.title && audit.description) { opportunities.push(`
  • ${audit.title}: ${audit.description.split('.')[0]}.
  • `); } } return ` SEO Report - ${targetUrl}

    SEO Analysis Report

    ${targetUrl}

    Mobile Scores

    ${mobileScores.performance}
    Performance
    ${mobileScores.accessibility}
    Accessibility
    ${mobileScores.bestPractices}
    Best Practices
    ${mobileScores.seo}
    SEO

    Desktop Scores

    ${desktopScores.performance}
    Performance
    ${desktopScores.accessibility}
    Accessibility
    ${desktopScores.bestPractices}
    Best Practices
    ${desktopScores.seo}
    SEO

    Core Web Vitals - Mobile

    MetricValueStatus
    Largest Contentful Paint (LCP) ${webVitals.mobile.lcp?.displayValue || 'N/A'} ${(webVitals.mobile.lcp?.numericValue || 0) <= 2500 ? 'Good' : (webVitals.mobile.lcp?.numericValue || 0) <= 4000 ? 'Needs Work' : 'Poor'}
    Total Blocking Time (TBT) ${webVitals.mobile.tbt?.displayValue || 'N/A'} ${(webVitals.mobile.tbt?.numericValue || 0) <= 200 ? 'Good' : (webVitals.mobile.tbt?.numericValue || 0) <= 600 ? 'Needs Work' : 'Poor'}
    Cumulative Layout Shift (CLS) ${webVitals.mobile.cls?.displayValue || 'N/A'} ${(webVitals.mobile.cls?.numericValue || 0) <= 0.1 ? 'Good' : (webVitals.mobile.cls?.numericValue || 0) <= 0.25 ? 'Needs Work' : 'Poor'}
    First Contentful Paint (FCP) ${webVitals.mobile.fcp?.displayValue || 'N/A'} ${(webVitals.mobile.fcp?.numericValue || 0) <= 1800 ? 'Good' : (webVitals.mobile.fcp?.numericValue || 0) <= 3000 ? 'Needs Work' : 'Poor'}
    Speed Index ${webVitals.mobile.si?.displayValue || 'N/A'} ${(webVitals.mobile.si?.numericValue || 0) <= 3400 ? 'Good' : (webVitals.mobile.si?.numericValue || 0) <= 5800 ? 'Needs Work' : 'Poor'}
    Time to Interactive (TTI) ${webVitals.mobile.tti?.displayValue || 'N/A'} ${(webVitals.mobile.tti?.numericValue || 0) <= 3800 ? 'Good' : (webVitals.mobile.tti?.numericValue || 0) <= 7300 ? 'Needs Work' : 'Poor'}

    Score Comparison

    Optimization Opportunities

      ${opportunities.slice(0, 10).join('\n ') || '
    • No significant issues found. Great job!
    • '}

    Generated on ${new Date().toLocaleString()}

    `; } async function main() { try { console.log('Starting SEO analysis for:', url); console.log(''); // Sequential requests to avoid rate limiting const mobile = await analyzeUrl(url, 'mobile'); const desktop = await analyzeUrl(url, 'desktop'); const report = generateReport(mobile, desktop, url); const fs = await import('fs'); const outputPath = './seo-report.html'; fs.writeFileSync(outputPath, report); // Print summary const m = mobile.lighthouseResult; const d = desktop.lighthouseResult; console.log(''); console.log('=== SEO Analysis Complete ==='); console.log(''); console.log('Mobile Scores:'); console.log(` Performance: ${Math.round(m.categories.performance.score * 100)}/100`); console.log(` Accessibility: ${Math.round(m.categories.accessibility.score * 100)}/100`); console.log(` Best Practices: ${Math.round(m.categories['best-practices'].score * 100)}/100`); console.log(` SEO: ${Math.round(m.categories.seo.score * 100)}/100`); console.log(''); console.log('Desktop Scores:'); console.log(` Performance: ${Math.round(d.categories.performance.score * 100)}/100`); console.log(` Accessibility: ${Math.round(d.categories.accessibility.score * 100)}/100`); console.log(` Best Practices: ${Math.round(d.categories['best-practices'].score * 100)}/100`); console.log(` SEO: ${Math.round(d.categories.seo.score * 100)}/100`); console.log(''); console.log('Core Web Vitals (Mobile):'); console.log(` LCP: ${m.audits['largest-contentful-paint']?.displayValue || 'N/A'}`); console.log(` TBT: ${m.audits['total-blocking-time']?.displayValue || 'N/A'}`); console.log(` CLS: ${m.audits['cumulative-layout-shift']?.displayValue || 'N/A'}`); console.log(''); console.log(`Report saved to: ${outputPath}`); console.log('Open the HTML file in a browser to view the interactive report.'); } catch (error) { console.error('Error:', error); process.exit(1); } } main(); ``` Run with: ```bash npx ts-node analyze.ts https://eng0.ai YOUR_API_KEY ``` ## Output The skill generates: 1. **Console Summary** - Quick overview of all scores 2. **seo-report.html** - Interactive HTML report with: - Mobile & Desktop score cards - Core Web Vitals table with status indicators - Radar chart comparing mobile vs desktop - Top optimization opportunities ## Metrics Explained ### Lighthouse Scores (0-100) - **Performance**: Page load speed and interactivity - **Accessibility**: How accessible the page is to users with disabilities - **Best Practices**: Modern web development standards - **SEO**: Search engine optimization basics ### Core Web Vitals | Metric | Good | Needs Work | Poor | |--------|------|------------|------| | LCP (Largest Contentful Paint) | < 2.5s | 2.5-4s | > 4s | | TBT (Total Blocking Time) | < 200ms | 200-600ms | > 600ms | | CLS (Cumulative Layout Shift) | < 0.1 | 0.1-0.25 | > 0.25 | ## API Details Uses Google PageSpeed Insights API v5: - **Free**: No API key required for basic usage - **Rate Limit**: ~25 requests per 100 seconds - **Data**: Real Lighthouse audit results ## Example Output ``` === SEO Analysis Complete === Mobile Scores: Performance: 89/100 Accessibility: 95/100 Best Practices: 100/100 SEO: 91/100 Core Web Vitals (Mobile): LCP: 1.8 s TBT: 150 ms CLS: 0.02 Report saved to: ./seo-report.html ```