import React, { useEffect, useState } from 'react'; import { __, sprintf } from '@wordpress/i18n'; import { api } from '../api'; import KeywordSuggest from '../components/KeywordSuggest'; import { Card, Button, Badge, Notice, MetricGrid, LineChart, PosBadge, Sparkline, ColumnChart, Delta, PageState, Field } from '../components/ui'; import { IconRefresh, IconX } from '../components/icons'; /** * The shared Delta, with the one thing it cannot know: absence. * * `change` is null until a keyword has two snapshots far enough apart, and * ±0 would claim "measured, no movement" — an em-dash is the honest value. * The number itself is already signed so that positive means climbed * (position 12 → 9 is +3), so no invert. */ function Change({ value }) { if (value === null || value === undefined) { return —; } return ; } function KeywordPlanner({ tracked, onTrack }) { const [status, setStatus] = useState(null); const [form, setForm] = useState({ client_id: '', client_secret: '', developer_token: '', customer_id: '', login_customer_id: '', language_id: '1000', geo_target_ids: '2784' }); const [seeds, setSeeds] = useState(''); const [pageUrl, setPageUrl] = useState(''); const [ideas, setIdeas] = useState([]); const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const [serp, setSerp] = useState(null); const [serpReport, setSerpReport] = useState(null); useEffect(() => { api.get('/rank/serp').then(setSerp).catch(() => setSerp(false)); api.get('/rank/planner/status').then((next) => { setStatus(next); setForm((old) => ({ ...old, ...next, client_secret: '', developer_token: '', geo_target_ids: (next.geo_target_ids || []).join(', ') })); }).catch(() => setStatus(false)); }, []); if (status === null || status === false) return null; const set = (key) => (e) => setForm((old) => ({ ...old, [key]: e.target.value })); const act = async (fn) => { setBusy(true); setError(null); try { await fn(); } catch (e) { setError(e.message); } finally { setBusy(false); } }; /** * Ask a search engine where the tracked keywords actually stand. Search * Console answers a different question — the average position of pages it * already shows — so a keyword the site does not rank for yet is simply * absent from it. */ const checkPositions = (force) => act(async () => { const r = await api.post('/rank/serp', { limit: 25, force }); setSerpReport(r); setSerp(await api.get('/rank/serp')); }); return ( <> {serp && serp.provider ? (
{sprintf( /* translators: %s: the provider being asked, e.g. Serper. */ __('Asking %s — each check spends one lookup from your quota.', 'ai-rank-suite'), serp.provider )}
{serpReport && (
{sprintf( /* translators: 1: keywords checked, 2: how many were found in the results, 3: keywords skipped, 4: failures. */ __('%1$s checked, %2$s found in the results, %3$s already done today, %4$s failed.', 'ai-rank-suite'), Number(serpReport.checked || 0).toLocaleString(), Number(serpReport.found || 0).toLocaleString(), Number(serpReport.skipped || 0).toLocaleString(), Number(serpReport.failed || 0).toLocaleString() )} {(serpReport.errors || []).length > 0 && (
    {serpReport.errors.slice(0, 5).map((e, i) => (
  • {e.keyword} — {e.message}
  • ))}
)}
)}
) : (

{__('No SERP provider is set up yet. Add one under SEO data providers and this becomes a daily position check for every keyword you track — including the ones you do not rank for yet, which Search Console cannot show you at all.', 'ai-rank-suite')}

)}
{error && {error}} {!status.configured ? (

{__('OAuth redirect URI:', 'ai-rank-suite')}{status.redirect_uri}

) : !status.connected ? (
{__('Not connected', 'ai-rank-suite')}
) : ( <>