import React, { useEffect, useState } from 'react'; import { __, sprintf } from '@wordpress/i18n'; import { api } from '../api'; import { Card, Button, Notice, MetricGrid, Badge } from './ui'; import Explain from './Explain'; import { IconRefresh, IconExternal } from './icons'; /** * The catalogue audit. * * Product SEO fails in a small number of ways and all of them are countable, * so this counts them rather than offering advice. The ordering is by what * each one costs: index bloat first because it is the most damaging and the * least visible, then dead ends, then the data gaps. */ export default function StoreAudit() { const [data, setData] = useState(null); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const load = (fresh = false) => { setBusy(true); api .get(`/store/audit${fresh ? '?fresh=1' : ''}`) .then(setData) .catch((e) => setError(e.message)) .finally(() => setBusy(false)); }; useEffect(() => { load(); }, []); if (error) return {error}; if (!data) return {__('Reading the catalogue…', 'ai-rank-suite')}; if (!data.active) return {__('WooCommerce is not active on this site.', 'ai-rank-suite')}; const c = data.counts || {}; const pct = (n) => (data.products > 0 ? Math.round((n / data.products) * 100) : 0); const go = (hash) => { window.location.hash = hash; }; return (
0 ? 'var(--ars-c-red-ink)' : undefined, sub: __('out of stock, still indexable', 'ai-rank-suite'), }, { id: 'thin', label: __('Thin descriptions', 'ai-rank-suite'), hint: __('Under 200 characters, there is nothing for a search engine to rank or an assistant to quote.', 'ai-rank-suite'), value: c.thin ?? '—', accent: pct(c.thin) > 25 ? 'var(--ars-c-red-ink)' : undefined, sub: sprintf(__('%d%% under 200 characters', 'ai-rank-suite'), pct(c.thin)), }, { id: 'gtin', label: __('No GTIN', 'ai-rank-suite'), hint: __('Google cannot match the product to the same item elsewhere without a global identifier.', 'ai-rank-suite'), value: c.no_gtin ?? '—', accent: pct(c.no_gtin) > 50 ? 'var(--ars-accent)' : undefined, sub: sprintf(__('%d%% cannot be matched', 'ai-rank-suite'), pct(c.no_gtin)), }, ]} /> {(data.issues || []).length > 0 ? ( load(true)}> {__('Re-check', 'ai-rank-suite')} } >
{data.issues.map((issue, i) => (
{issue.level === 'error' ? '✕' : '!'}
{issue.title}
{issue.text}
{FIX[issue.fix] && ( )}
))}
) : ( {__('Nothing in the catalogue is failing the checks above.', 'ai-rank-suite')} )}
{[ [__('No SKU', 'ai-rank-suite'), c.no_sku, __('Not required by Google, but every feed and every integration wants one.', 'ai-rank-suite')], [ __('No GTIN', 'ai-rank-suite'), c.no_gtin, __('Google cannot match the product to the same item elsewhere without it.', 'ai-rank-suite'), ], [__('No price', 'ai-rank-suite'), c.no_price, __('A product with no price cannot be a rich result at all.', 'ai-rank-suite')], [__('No image', 'ai-rank-suite'), c.no_image, __('No Shopping listing, no image in the result, a grey box when shared.', 'ai-rank-suite')], [ __('No short description', 'ai-rank-suite'), c.no_short_desc, __('WooCommerce shows it beside the price; it is also the best source for a meta description.', 'ai-rank-suite'), ], [ __('No meta description', 'ai-rank-suite'), c.no_meta_desc, __('The autopilot can write these for the whole catalogue in one run.', 'ai-rank-suite'), ], [__('Out of stock', 'ai-rank-suite'), c.out_of_stock, __('Fine in itself. The problem is only the indexable ones.', 'ai-rank-suite')], ].map(([label, value, why]) => ( ))}
{label}
{why}
0 ? 'var(--ars-ink)' : 'var(--ars-ink-3)' }}>{value} {value > 0 && data.products > 0 && (
{pct(value)}%
)}
{(data.categories?.rows || []).length === 0 ? (

{__('Every category with products in it has a description.', 'ai-rank-suite')}

) : (
{data.categories.rows.map((r) => ( ))}
{__('Category', 'ai-rank-suite')} {__('Products', 'ai-rank-suite')} {__('Words', 'ai-rank-suite')}
{r.name} {r.products} {r.words}
)}
100 ? 'var(--ars-c-red-ink)' : undefined, }, { id: 'open', label: __('Unblocked parameters', 'ai-rank-suite'), hint: __('Filter parameters no robots.txt rule names — a crawler may follow every combination of them.', 'ai-rank-suite'), value: (data.facets?.open || []).length, accent: (data.facets?.open || []).length > 0 ? 'var(--ars-accent)' : undefined, sub: sprintf(__('%d named in robots.txt', 'ai-rank-suite'), (data.facets?.guarded || []).length), }, ]} />
{(data.facets?.guarded || []).map((p) => ( {p} ))} {(data.facets?.open || []).map((p) => ( {p} ))}

{__('A shop with six filter attributes can generate more crawlable URLs than it has products — every one a near-duplicate of a category page, every one competing with the category page it came from. Google spends its crawl budget on them instead of your products, and the category page it should have ranked is diluted across a thousand variants of itself.', 'ai-rank-suite')}

{__('None of those URLs exist until a crawler follows a filter link, which is why the problem is invisible from the admin and why it is usually found months later in a Search Console coverage report. The fix is to disallow the parameters in robots.txt — the AI Crawlers screen writes robots.txt, and the Advanced screen has the raw editor.', 'ai-rank-suite')}

{__('The count above is the number of parameters in play and whether anything names them in robots.txt. It is deliberately not a count of junk URLs, because nobody can know that without crawling the site, and a made-up number here would be worse than none.', 'ai-rank-suite')}

{(data.thin_list || []).length > 0 && ( go('/autopilot')}>{__('Open the autopilot', 'ai-rank-suite')} } flush >
{data.thin_list.map((p) => ( go(`/content/${p.id}`)}> ))}
{__('Product', 'ai-rank-suite')} {__('SKU', 'ai-rank-suite')} {__('Characters', 'ai-rank-suite')}
{p.title} {p.sku || '—'} {p.body === 0 ? {__('empty', 'ai-rank-suite')} : p.body}
)}
); } const FIX = { crawl: { hash: '/crawlers', label: __('Open crawler controls', 'ai-rank-suite') }, content: { hash: '/content?type=product', label: __('Open the product list', 'ai-rank-suite') }, products: { hash: '/content?type=product', label: __('Open the product list', 'ai-rank-suite') }, categories: { hash: '/schema', label: __('Open schema settings', 'ai-rank-suite') }, autopilot: { hash: '/autopilot', label: __('Let the autopilot write them', 'ai-rank-suite') }, };