/* global React, Icon */ const { useState, useEffect } = React; function Analytics({ goto }) { const [days, setDays] = useState(7); const [data, setData] = useState(null); const [error, setError] = useState(null); const [ga4, setGa4] = useState(null); useEffect(() => { fetch(`/api/analytics/overview?days=${days}`, { credentials: 'include' }) .then((r) => r.ok ? r.json() : Promise.reject(r.statusText)) .then(setData) .catch((e) => setError(String(e))); fetch(`/api/analytics/ga4?days=${days}`, { credentials: 'include' }) .then((r) => r.ok ? r.json() : { connected: false, reason: r.statusText }) .then(setGa4) .catch(() => setGa4({ connected: false, reason: 'fetch failed' })); }, [days]); if (error) { return
Failed to load: {error}
; } if (!data) { return
Loading…
; } const k = data.kpi; const m = data.messaging; return (
Insights

Analytics

{[ { v: 7, l: '7d' }, { v: 14, l: '14d' }, { v: 30, l: '30d' }, { v: 90, l: '90d' }, ].map((o) => ( ))}
{/* Top KPIs */}
{/* Bookings + replies row */}
0 ? `${Math.round((k.replies_week / k.new_contacts_week) * 100)}%` : '—'} sub={`replies / new contacts`} />
{/* Messaging panel */}

Messaging volume

{/* Email engagement */}

Email engagement

Tracking via Resend webhook (open/click pixel + link rewrite). Gmail-direct sends are tracked as sent only — Google doesn't expose opens.
{/* Pipeline distribution */}

Pipeline distribution

{/* GA4 — lineagroup.ae website */}

Website · lineagroup.ae (GA4)

{!ga4 &&
Loading GA4…
} {ga4 && !ga4.connected && (
Not connected
{ga4.reason}
{ga4.needs_reauth && ( Re-authorize Google to grant Analytics scope )}
)} {ga4 && ga4.connected && } {/* Plug-in placeholders */}

External integrations

Window: last {days} days · Generated {new Date(data.generated_at).toLocaleString()}
); } function fmt(n) { if (n == null) return '0'; if (window.fmtAED) return window.fmtAED(n); return Math.round(n).toLocaleString(); } function Kpi({ label, value, sub, accent }) { return (
{label}
{value}
{sub &&
{sub}
}
); } function Stat({ label, value, mono, accent }) { return (
{label}
{value}
); } function ChannelCard({ label, data, dot }) { return (
{label}
Sent {data.sent_today}
Received {data.received_today}
All-time {data.sent_total} / {data.received_total}
); } function PipelineBars({ stages }) { const entries = Object.entries(stages || {}); if (entries.length === 0) return
No contacts yet.
; const max = Math.max(...entries.map(([, n]) => n)); return (
{entries.map(([stage, n]) => (
{stage}
{n}
))}
); } function PlaceholderCard({ title, status, note, cta }) { const isConnected = status === 'Connected'; return (
{title} {status}
{note}
{cta && ( )}
); } function Ga4Panel({ ga4 }) { const k = ga4.kpi || {}; const rt = ga4.realtime || {}; return (
0 ? 'var(--accent)' : 'var(--text-dim)', boxShadow: rt.active_users > 0 ? '0 0 12px var(--accent)' : 'none' }}>
Active users right now
Property {ga4.property_id} · last 30 min
{rt.active_users || 0}
Top pages
{(ga4.top_pages || []).length === 0 &&
No data yet.
} {(ga4.top_pages || []).slice(0, 8).map((p, i) => (
0 ? '1px solid var(--divider)' : 'none' }}>
{p.path || '/'} {p.title && · {p.title}}
{p.views}
))}
Traffic sources
{(ga4.sources || []).length === 0 &&
No data yet.
} {(ga4.sources || []).slice(0, 8).map((s, i) => (
0 ? '1px solid var(--divider)' : 'none' }}> {s.channel} {s.users}u {s.sessions}s
))}
); } Object.assign(window, { Analytics });