SEO Analysis

Overview

The SEO analysis features provide tools to analyze web pages for SEO issues, focusing on best practices for Australian websites.

The implementation combines static analysis of HTML content with AI-powered analysis using OpenAI to provide comprehensive SEO reports.

Features

  • Basic SEO checks for common issues (missing title tags, meta descriptions, canonical URLs, etc.)
  • AI-powered analysis using OpenAI for more complex SEO issues
  • Support for both synchronous and asynchronous (queued) analysis
  • Configuration options to customize the analysis behavior
  • Service class with a simple API for developers

Configuration

The following configuration options are available in the config/textstem.php file:

'seo' => [
    'enabled' => env('SEO_ENABLED', true),
    'use_queue' => env('SEO_USE_QUEUE', true),
    'use_ai' => env('SEO_USE_AI', true),
    'check_on_save' => env('SEO_CHECK_ON_SAVE', false),
    'store_reports' => env('SEO_STORE_REPORTS', true),
    'report_retention_days' => env('SEO_REPORT_RETENTION_DAYS', 30),
],
  • enabled: Whether SEO analysis is enabled
  • use_queue: Whether to use a queue for SEO analysis (recommended for production)
  • use_ai: Whether to use AI for more comprehensive SEO analysis
  • check_on_save: Whether to automatically check SEO when saving content
  • store_reports: Whether to store SEO reports
  • report_retention_days: How long to retain SEO reports (in days)

Usage

Using the Facade

The easiest way to use the SEO analysis features is through the SEO facade:

use Medialight\Textstem\Facades\SEO;

// Analyze a URL
$report = SEO::analyzeUrl('https://example.com');

// Analyze HTML content
$html = '<html>...</html>';
$report = SEO::analyzeHtml('https://example.com', $html);

// Analyze with a callback (useful for queued analysis)
SEO::analyzeUrl('https://example.com', function ($report) {
    // Do something with the report
    Log::info('SEO report generated', $report);
});

// Get configuration values
$checkOnSave = SEO::shouldCheckOnSave();
$storeReports = SEO::shouldStoreReports();
$retentionDays = SEO::getReportRetentionDays();

Using the Service Class

You can also use the SEOService class directly via dependency injection:

use Medialight\Textstem\Services\SEOService;

class MyController
{
    protected $seoService;

    public function __construct(SEOService $seoService)
    {
        $this->seoService = $seoService;
    }

    public function checkUrl(Request $request)
    {
        $url = $request->input('url');
        $report = $this->seoService->analyzeUrl($url);

        return view('seo-report', ['report' => $report]);
    }
}

Or you can resolve it from the container:

$service = app(SEOService::class);
$report = $service->analyzeUrl('https://example.com');

Report Structure

The SEO report has the following structure:

[
    'url' => 'https://example.com',
    'timestamp' => '2023-06-01T12:34:56+00:00',
    'score' => 85,
    'basic_issues' => [
        [
            'type' => 'error',
            'code' => 'missing-title',
            'message' => 'Page is missing a title tag',
            'element' => ['tag' => 'head', 'snippet' => '<head>...</head>'],
            'impact' => 'critical',
        ],
        // More issues...
    ],
    'ai_analysis' => [
        'summary' => 'The page has several SEO issues...',
        'critical_issues' => [
            'Missing title tag...',
            // More critical issues...
        ],
        'important_issues' => [
            'Meta description is too short...',
            // More important issues...
        ],
        'minor_issues' => [
            'Missing Open Graph tags...',
            // More minor issues...
        ],
        'recommendations' => [
            'Add a descriptive title tag...',
            // More recommendations...
        ],
        'score' => 85,
    ],
]

Using the Helper Class Directly

For more advanced use cases, you can use the SEOHelper class directly:

use Medialight\Textstem\Helpers\SEOHelper;

// Perform basic SEO checks
$issues = SEOHelper::basicSEOChecks($html);

// Prepare HTML for OpenAI analysis
$preparedHtml = SEOHelper::prepareHtmlForAnalysis($html);

// Generate a prompt for OpenAI
$prompt = SEOHelper::generateSEOPrompt($preparedHtml, $url);

// Parse the OpenAI response
$analysis = SEOHelper::parseSEOResponse($response);

Using the Job Class

For background processing, you can dispatch the SEOAnalysisJob directly:

use Medialight\Textstem\Jobs\SEOAnalysisJob;

// Dispatch the job
SEOAnalysisJob::dispatch('https://example.com', $html, function ($report) {
    // Do something with the report
    Log::info('SEO report generated', $report);
});

Australian SEO Best Practices

Australian SEO best practices include:

  1. Local Targeting: Using .com.au domains and including location-specific keywords for Australian audiences.
  2. Mobile Optimization: Ensuring websites are mobile-friendly, as mobile usage is high in Australia.
  3. Page Speed: Optimizing for fast loading times, especially important for Australian users who may experience slower internet speeds in some regions.
  4. Local Business Listings: Registering with Google My Business and other local directories.
  5. Content Quality: Creating high-quality, original content that addresses Australian audiences' specific needs and interests.
  6. Compliance: Ensuring websites comply with Australian privacy laws and regulations.

For more information, see:

Benefits

Implementing SEO analysis in your website provides several benefits:

  1. Visibility: Improves your website's visibility in search engine results.
  2. Traffic: Increases organic traffic to your website.
  3. User Experience: Many SEO improvements also enhance the user experience.
  4. Competitiveness: Helps you stay competitive in the Australian market.
  5. Conversion Rates: Better SEO often leads to higher conversion rates.