import React, { useEffect, useState } from 'react'; import { __, sprintf } from '@wordpress/i18n'; import { api } from '../api'; import { Card, Button, Badge, Notice, Field, Switch, MetricGrid, Sparkline, RankBar, SegmentBar } from './ui'; import Explain from './Explain'; import { IconChart, IconRefresh, IconSparkle, IconExternal } from './icons'; /** * Matomo. * * Two reasons it is here, and the second is the interesting one. Plenty of * sites cannot use Google Analytics at all, so a paid SEO plugin that only * speaks GA4 is unusable for them. And the only hard evidence that any of this * work is paying off is a visit whose referrer is an AI assistant — Matomo * returns the full referrer list unsampled and without a processing delay, so * that question has an exact answer here rather than an estimate. */ export default function MatomoPanel({ settings, onSave, saving }) { const [data, setData] = useState(null); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const [token, setToken] = useState(''); const [verified, setVerified] = useState(null); const [days, setDays] = useState(30); const [draft, setDraft] = useState(null); const s = draft || settings || {}; const load = (d = days) => { setBusy(true); setError(null); api .get(`/analytics/matomo?days=${d}`) .then(setData) .catch((e) => setError(e.message)) .finally(() => setBusy(false)); }; useEffect(() => { load(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const patch = (p) => setDraft({ ...s, ...p }); const saveAll = async () => { setBusy(true); setError(null); try { // The token goes to its own endpoint because it is stored // encrypted and never comes back — sending it with the settings // would mean the settings payload carried a secret it cannot show. if (token) { await api.put('/analytics/matomo', { token }); setToken(''); } await onSave(s); setDraft(null); load(); } catch (e) { setError(e.message); } finally { setBusy(false); } }; const verify = async () => { setBusy(true); setVerified(null); setError(null); try { setVerified(await api.post('/analytics/matomo/verify')); } catch (e) { setError(e.message); } finally { setBusy(false); } }; const ai = data?.assistants; return (
{error && {error}} {data?.configured && ai && ( } title={__('Visits from AI assistants', 'ai-rank-suite')} subtitle={__('Real people who arrived from an AI answer — the only hard evidence that being cited is working', 'ai-rank-suite')} action={
} > 0 ? (data.totals.actions / data.totals.visits).toFixed(1) : '—', sub: sprintf(__('%s%% bounced', 'ai-rank-suite'), data.totals?.bounce || 0), }, ]} /> {ai.engines.length > 0 ? (
({ label: e.name, value: e.visits }))} max={Math.max(...ai.engines.map((e) => e.visits))} color="var(--ars-brand)" format={(v) => sprintf(__('%s visits', 'ai-rank-suite'), v.toLocaleString())} />
) : ( {__('No visits from a named AI assistant in this period. That is normal early on — being cited takes weeks to turn into clicks, and many assistants strip the referrer entirely, so this number is a floor rather than a total.', 'ai-rank-suite')} )} {data.series?.length > 1 && (
{__('Visits per day', 'ai-rank-suite')}
d.value)} height={44} color="var(--ars-brand)" />
)}
)} {data?.configured && (data.channels || []).length > 0 && (
({ label: c.label, value: c.visits, color: ['var(--ars-series-1)', 'var(--ars-series-2)', 'var(--ars-series-3)', 'var(--ars-series-4)', 'var(--ars-ink-3)'][i % 5], }))} />
{(data.pages || []).slice(0, 10).map((p, i) => ( ))}
{__('Page', 'ai-rank-suite')} {__('Views', 'ai-rank-suite')}
{p.path} {p.views.toLocaleString()}
)} } title={__('Matomo connection', 'ai-rank-suite')} subtitle={__('Your own Matomo — self-hosted or Matomo Cloud. Nothing is proxied anywhere.', 'ai-rank-suite')} action={
{data?.configured && {__('Connected', 'ai-rank-suite')}}
} >
patch({ matomo_url: e.target.value })} /> patch({ matomo_site_id: Number(e.target.value) })} /> setToken(e.target.value)} />
{verified && ( <> {verified.name || __('Connected', 'ai-rank-suite')} {!verified.matches && ( {sprintf(__('That Matomo site is set up for %s, not this one — the report would be somebody else’s traffic.', 'ai-rank-suite'), verified.main_url || __('another address', 'ai-rank-suite'))} )} )}
patch({ matomo_enabled: v })} label={__('Read reports from Matomo', 'ai-rank-suite')} /> patch({ matomo_track: v })} label={__('Also add the tracking code to the site', 'ai-rank-suite')} /> {s.matomo_track && (
patch({ matomo_cookieless: v })} label={__('Track without cookies', 'ai-rank-suite')} />

{__('Cookieless is on by default. Matomo can measure without setting a cookie, and a site that chose Matomo over Google Analytics has usually chosen it for exactly that reason. Leave the tracking code off if Matomo is already installed by another plugin or by your theme — two snippets means every visit counted twice.', 'ai-rank-suite')}

)}

{__('A visit is attributed to an assistant only when the browser sends a referrer naming it. Several assistants strip the referrer entirely, some open links in an in-app browser that sends nothing, and anyone who reads an answer and then types your name into a search box arrives as organic search. So the real influence of AI answers is always larger than this figure — treat it as the part you can prove.', 'ai-rank-suite')}

{__('The direction still matters more than the level. If this number is climbing month over month while your published pages are unchanged, the citations are working.', 'ai-rank-suite')}

{__('How to create a Matomo auth token', 'ai-rank-suite')}

); }