import { useState } from 'react'; import { Header } from './components/Header'; import { useAnalytics } from './hooks/useAnalytics'; import { AIDiscoveryTrafficCard } from './components/cards/AIDiscoveryTrafficCard'; import { AIReferredVisitsCard } from './components/cards/AIReferredVisitsCard'; import { TopPagesCard } from './components/cards/TopPagesCard'; import { NonAIUsersCard } from './components/cards/NonAIUsersCard'; import { CrawlerLogsCard } from './components/cards/CrawlerLogsCard'; import { HumanLogsCard } from './components/cards/HumanLogsCard'; import { RecommendedActionsCard } from './components/cards/RecommendedActionsCard'; import { WinsCard } from './components/cards/WinsCard'; import { api, type Period } from './lib/api'; function extractDomain(url: string): string { try { return new URL(url).hostname.replace(/^www\./, ''); } catch { return url; } } export default function App() { const [period, setPeriod] = useState('7d'); const [enabling, setEnabling] = useState(false); const [enableError, setEnableError] = useState(null); const { data, loading, error, refresh } = useAnalytics(period); const domain = window.ezyAiBoot?.siteUrl ? extractDomain(window.ezyAiBoot.siteUrl) : undefined; if (error) { return (

Couldn't load analytics

{error}

); } if (loading && !data) { return (
); } if (!data) return null; const trackingOff = data.tracking_enabled === false; // Enable analytics without leaving the page. The /settings route is // manage_options-gated server-side, so this is the same authority the // Settings screen uses — it just saves the user a round trip. async function enableAnalytics() { setEnabling(true); setEnableError(null); try { await api.updateSettings({ enable_analytics: true }); await refresh(); } catch (e) { setEnableError(e instanceof Error ? e.message : 'Could not enable analytics.'); } finally { setEnabling(false); } } return (
{trackingOff && (
Analytics

Turn on analytics to start tracking AI visits.

Visitor analytics is off, so nothing is being recorded yet. Enable it to see which AI crawlers reach your site, which pages they read, and which visitors arrive from ChatGPT, Claude and Perplexity.

{enableError && (

{enableError} You can also enable it from the Settings page.

)}
)}
); }