$config ) :
$history = AWBSEO_Rank_Tracker::get_history( $kw, 30 );
$latest = $history ? end( $history ) : null;
$pos = $latest ? (int) $latest->position : '-';
// If no history yet and a rank data source is available, fetch
// live and store so subsequent page loads use the cached
// table value. Previously this only fired when GSC was
// connected, so a site relying solely on the Rank Tracker
// API key never got this same-page backfill.
if ( '-' === $pos && $has_rank_source ) {
$live_pos = AWBSEO_Rank_Tracker::fetch_position( $kw );
if ( $live_pos !== null ) {
$pos = $live_pos;
// Rebuild history so the sparkline picks it up too.
$history = AWBSEO_Rank_Tracker::get_history( $kw, 30 );
}
}
?>