GSC integration provides keyword rank tracking, content decay detection, and daily sync via cron. PRO feature.
OAuth Flow
- Admin enters Google OAuth Client ID and Secret in Settings
- User clicks “Connect” and authorizes via Google’s consent screen
- Plugin exchanges the authorization code for access + refresh tokens
- 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 ], ... ]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();—