Overview
TheGeoAI_Analyzer class provides AI-powered content analysis using the Google Gemini API. It analyzes posts for SEO optimization, generates meta content, and tests API connectivity. This class uses the singleton pattern and includes the Encryption trait.
Namespace: GeoAI\Core
Location: includes/class-geoai-analyzer.php
Key Features
- AI-powered SEO content auditing
- Automatic analysis on post publish
- Meta title and description generation
- Answer engine optimization (Google AI Overviews, Perplexity, ChatGPT)
- API connection testing
- Background processing support via Action Scheduler
Public Methods
get_instance()
Returns the singleton instance of the analyzer class.GeoAI_Analyzer - The singleton instance
Example:
analyze_post()
Analyzes a post using Google Gemini AI and returns comprehensive SEO audit data.The ID of the post to analyze
array|WP_Error - Audit results or error object
Response Structure:
maybe_auto_analyze()
Automatically analyzes post on save if auto-run is enabled.The post ID being saved
The post object being saved
save_post (priority 20)
Behavior:
- Only runs on published posts
- Skips revisions and autosaves
- Checks if auto-run is enabled in settings
- Uses Action Scheduler if available for background processing
handle_background_audit()
Handles scheduled background audit tasks.Post ID (can be int or array from scheduler)
geoai_background_audit
Example:
generate_meta_content()
Generates AI-powered meta title and description for a post.The post ID to generate meta content for
array|WP_Error - Array with ‘title’ and ‘description’ keys, or error
Response:
test_api_connection()
Tests the Google Gemini API connection.Optional API key to test (defaults to saved key)
array|WP_Error - Success message or error
Example:
Audit Metrics
Score Components
Score 0-100 measuring how well content answers user queries
Score 0-100 measuring content organization and formatting
Score 0-100 measuring authority and credibility signals
Score 0-100 measuring technical SEO implementation
Overall score 0-100 (weighted average of components)
Issue Severity Levels
- high - Critical issues that significantly impact SEO
- med - Medium priority issues that should be addressed
- low - Minor suggestions for improvement
API Configuration
Gemini API Endpoint
The analyzer uses the Gemini 1.5 Flash model:Generation Settings
For Audits:- Temperature: 0.3 (more deterministic)
- Top K: 40
- Top P: 0.95
- Max Tokens: 2048
- Response Format: JSON
- Temperature: 0.7 (more creative)
- Top K: 40
- Top P: 0.95
- Max Tokens: 512
- Response Format: JSON
Storage and Caching
Post Meta Keys
JSON-encoded audit results from last analysis
MySQL timestamp of last audit run
Retrieving Cached Audits
Error Handling
Common Error Codes
Post not found or invalid post ID
Google Gemini API key not configured in settings
API request failed or returned non-200 status code
Failed to parse JSON response from Gemini API
API response missing required fields
Usage Examples
Manual Post Analysis
Generate and Save Meta Content
Test API Before Saving Key
Optimization Tips
Content Length Limits
- Audit content: First 20,000 characters
- Meta generation: First 5,000 characters
Background Processing
For better performance, install Action Scheduler:Related Classes
- GeoAI_Admin - Admin interface and settings
- GeoAI_Meta - Meta tag output
- GeoAI_REST_API - REST API endpoints