23. Google Search Console Integration | SEO Forge - Rank Higher with AI-Powered SEO
Download Log in

23. Google Search Console Integration

Developer Guide

GSC integration provides keyword rank tracking, content decay detection, and daily sync via cron. PRO feature.

OAuth Flow

  1. Admin enters Google OAuth Client ID and Secret in Settings
  2. User clicks “Connect” and authorizes via Google’s consent screen
  3. Plugin exchanges the authorization code for access + refresh tokens
  4. Tokens are stored in wp_options

Fetching Rankings

php
$gsc = SEOFORGE_GSC::instance();

if ( ! $gsc->is_connected() ) {
    return;
}

// Get keyword rankings for the last 28 days
$rankings = $gsc->get_keyword_rankings( 28, 100 );
// Returns: [ [ 'keyword' => '...', 'clicks' => 150, 'impressions' => 5200, 'ctr' => 2.9, 'position' => 8.3 ], ... ]

// Get rankings for a specific page URL
$page_rankings = $gsc->get_page_rankings( 'https://example.com/my-post/', 28 );

Content Decay Detection

Compares the last 28 days vs the previous 28 days to find pages losing traffic:

php
$decay = $gsc->detect_content_decay();
// Returns: [ [ 'url' => '...', 'post_id' => 42, 'clicks_now' => 15, 'clicks_prev' => 50,
//   'click_change' => -70, 'position_now' => 12.5, 'position_prev' => 5.2 ], ... ]
Decay criteria: clicks dropped >30% OR position worsened by >3 spots.

Cron Sync

A daily cron event seoforge_daily_gsc_sync refreshes cached rankings and decay data:

php
$rankings = get_option( 'seoforge_gsc_rankings_cache', [] );
$decay    = get_option( 'seoforge_gsc_decay_cache', [] );
$last     = get_option( 'seoforge_gsc_last_sync', 0 );

// Disconnect GSC
SEOFORGE_GSC::instance()->disconnect();

Forge AI Assistant Online

Hi! I'm the SEO Forge AI assistant. Ask me anything about the plugin — setup, features, troubleshooting, or development.

Just now
Powered by Forge AI · Browse docs