diff --git a/backend/app/ops_panel.py b/backend/app/ops_panel.py
index 40bc4ee..c50deb7 100644
--- a/backend/app/ops_panel.py
+++ b/backend/app/ops_panel.py
@@ -279,6 +279,18 @@ def website_analytics(website_id: str, range_key: str = "7d") -> dict[str, Any]:
code_browser, browsers = _umami_request(
"GET", f"/api/websites/{website_id}/metrics", token=token, query={**q, "type": "browser", "limit": 6}
)
+ code_os, oses = _umami_request(
+ "GET", f"/api/websites/{website_id}/metrics", token=token, query={**q, "type": "os", "limit": 6}
+ )
+ code_lang, langs = _umami_request(
+ "GET", f"/api/websites/{website_id}/metrics", token=token, query={**q, "type": "language", "limit": 8}
+ )
+ code_city, cities = _umami_request(
+ "GET", f"/api/websites/{website_id}/metrics", token=token, query={**q, "type": "city", "limit": 8}
+ )
+ code_title, titles = _umami_request(
+ "GET", f"/api/websites/{website_id}/metrics", token=token, query={**q, "type": "title", "limit": 8}
+ )
stats_obj = stats if isinstance(stats, dict) else {}
pageviews_n = int(stats_obj.get("pageviews") or 0)
@@ -304,6 +316,10 @@ def website_analytics(website_id: str, range_key: str = "7d") -> dict[str, Any]:
"active": None if code_active == 200 else active,
"pageviews": None if code_pv == 200 else pageviews,
"path": None if code_path == 200 else paths,
+ "os": None if code_os == 200 else oses,
+ "language": None if code_lang == 200 else langs,
+ "city": None if code_city == 200 else cities,
+ "title": None if code_title == 200 else titles,
},
"active": int((active or {}).get("visitors") or 0) if isinstance(active, dict) else 0,
"stats": {
@@ -321,6 +337,10 @@ def website_analytics(website_id: str, range_key: str = "7d") -> dict[str, Any]:
"top_countries": _metric_list(countries),
"top_devices": _metric_list(devices),
"top_browsers": _metric_list(browsers),
+ "top_os": _metric_list(oses),
+ "top_languages": _metric_list(langs),
+ "top_cities": _metric_list(cities),
+ "top_titles": _metric_list(titles),
"umami_url": umami_config()["url"],
}
diff --git a/frontend/src/app/ops/page.tsx b/frontend/src/app/ops/page.tsx
index 02a75dd..11d8034 100644
--- a/frontend/src/app/ops/page.tsx
+++ b/frontend/src/app/ops/page.tsx
@@ -16,6 +16,7 @@ import {
ShieldCheck,
Users,
Wifi,
+ X,
} from "lucide-react";
import { Shell } from "@/components/Shell";
@@ -73,6 +74,7 @@ type AnalyticsDetail = {
bounces?: number;
bounce_rate?: number;
avg_visit_sec?: number;
+ totaltime?: number;
};
series?: { x: string; y: number }[];
top_paths?: { name: string; value: number }[];
@@ -80,6 +82,10 @@ type AnalyticsDetail = {
top_countries?: { name: string; value: number }[];
top_devices?: { name: string; value: number }[];
top_browsers?: { name: string; value: number }[];
+ top_os?: { name: string; value: number }[];
+ top_languages?: { name: string; value: number }[];
+ top_cities?: { name: string; value: number }[];
+ top_titles?: { name: string; value: number }[];
umami_url?: string;
};
@@ -196,6 +202,169 @@ function MetricList({ title, rows }: { title: string; rows?: { name: string; val
);
}
+function SiteDetailBody({
+ detail,
+ loading,
+}: {
+ detail: AnalyticsDetail | null;
+ loading?: boolean;
+}) {
+ const st = detail?.stats;
+ if (loading && !detail) {
+ return (
+
+ 加载访客详情…
+
+ );
+ }
+ if (!detail) {
+ return 暂无该站点数据
;
+ }
+ return (
+
+
+ {[
+ { label: "浏览量 PV", value: fmtNum(st?.pageviews), icon: Eye },
+ { label: "独立访客", value: fmtNum(st?.visitors), icon: Users },
+ { label: "访问次数", value: fmtNum(st?.visits), icon: MousePointerClick },
+ { label: "跳出率", value: `${st?.bounce_rate ?? 0}%`, icon: Activity },
+ { label: "平均停留", value: fmtDuration(st?.avg_visit_sec), icon: Radar },
+ ].map((card) => (
+
+
+
+ {card.label}
+
+
{card.value}
+
+ ))}
+
+
+
+
+ 浏览量趋势
+ 当前在线 {detail.active ?? 0}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ );
+}
+
+function SiteDetailModal({
+ open,
+ domain,
+ role,
+ range,
+ detail,
+ loading,
+ onClose,
+ onRange,
+ umamiUrl,
+}: {
+ open: boolean;
+ domain: string;
+ role?: string;
+ range: string;
+ detail: AnalyticsDetail | null;
+ loading?: boolean;
+ onClose: () => void;
+ onRange: (id: string) => void;
+ umamiUrl?: string;
+}) {
+ useEffect(() => {
+ if (!open) return;
+ const onKey = (e: KeyboardEvent) => {
+ if (e.key === "Escape") onClose();
+ };
+ window.addEventListener("keydown", onKey);
+ const prev = document.body.style.overflow;
+ document.body.style.overflow = "hidden";
+ return () => {
+ window.removeEventListener("keydown", onKey);
+ document.body.style.overflow = prev;
+ };
+ }, [open, onClose]);
+
+ if (!open) return null;
+
+ return (
+
+
e.stopPropagation()}
+ >
+
+
+
站点访客详情
+
{domain}
+ {role ?
{role}
: null}
+
+
+
+ {RANGES.map((r) => (
+
+ ))}
+
+
+ Umami
+
+
+
+
+
+ {loading ? (
+
+ 刷新中
+
+ ) : null}
+
+
+
+
+ );
+}
+
export default function OpsPage() {
const toast = useToast();
const now = useNow(1000);
@@ -204,6 +373,8 @@ export default function OpsPage() {
const [overview, setOverview] = useState([]);
const [detail, setDetail] = useState(null);
const [domain, setDomain] = useState("dylive.nomadro.com");
+ const [modalOpen, setModalOpen] = useState(false);
+ const [modalLoading, setModalLoading] = useState(false);
const [range, setRange] = useState("7d");
const [loading, setLoading] = useState(true);
const [syncing, setSyncing] = useState(false);
@@ -219,9 +390,11 @@ export default function OpsPage() {
const domainRef = useRef(domain);
const rangeRef = useRef(range);
const tabRef = useRef(tab);
+ const modalOpenRef = useRef(modalOpen);
domainRef.current = domain;
rangeRef.current = range;
tabRef.current = tab;
+ modalOpenRef.current = modalOpen;
useEffect(() => {
const onVis = () => setPageVisible(document.visibilityState === "visible");
@@ -238,16 +411,22 @@ export default function OpsPage() {
else setSyncing(true);
try {
const tasks: Promise[] = [];
- // Always keep analytics fresh on analytics tab; monitor on monitor tab;
- // still refresh both lightly so switching tabs feels live.
tasks.push(
(async () => {
const ov = await fetchJson(`/api/ops/analytics?range=${encodeURIComponent(rangeRef.current)}`);
setOverview(ov?.sites || []);
- const d = await fetchJson(
- `/api/ops/analytics?range=${encodeURIComponent(rangeRef.current)}&domain=${encodeURIComponent(domainRef.current)}`
- );
- setDetail(d);
+ // Only pull heavy site detail while modal is open (or first paint needs it)
+ if (modalOpenRef.current && domainRef.current) {
+ setModalLoading(true);
+ try {
+ const d = await fetchJson(
+ `/api/ops/analytics?range=${encodeURIComponent(rangeRef.current)}&domain=${encodeURIComponent(domainRef.current)}`
+ );
+ setDetail(d);
+ } finally {
+ setModalLoading(false);
+ }
+ }
})()
);
tasks.push(
@@ -271,6 +450,46 @@ export default function OpsPage() {
}
}, [toast]);
+ const openSiteModal = useCallback(
+ async (d: string) => {
+ setDomain(d);
+ setModalOpen(true);
+ setModalLoading(true);
+ try {
+ const detailRes = await fetchJson(
+ `/api/ops/analytics?range=${encodeURIComponent(rangeRef.current)}&domain=${encodeURIComponent(d)}`
+ );
+ setDetail(detailRes);
+ } catch (e) {
+ toast.push((e as Error).message || "加载详情失败", "err");
+ } finally {
+ setModalLoading(false);
+ }
+ },
+ [toast]
+ );
+
+ const closeSiteModal = useCallback(() => setModalOpen(false), []);
+
+ const onModalRange = useCallback(
+ async (id: string) => {
+ setRange(id);
+ if (!domainRef.current) return;
+ setModalLoading(true);
+ try {
+ const detailRes = await fetchJson(
+ `/api/ops/analytics?range=${encodeURIComponent(id)}&domain=${encodeURIComponent(domainRef.current)}`
+ );
+ setDetail(detailRes);
+ } catch (e) {
+ toast.push((e as Error).message || "切换时间失败", "err");
+ } finally {
+ setModalLoading(false);
+ }
+ },
+ [toast]
+ );
+
// Poll server continuously while page is visible (no manual refresh required).
useAutoRefresh(loadSilent, {
intervalMs: tab === "analytics" ? 10000 : 12000,
@@ -286,9 +505,9 @@ export default function OpsPage() {
const dnsOkCount = useMemo(() => (data?.sites || []).filter((s) => s.dns_ok).length, [data]);
const svcOkCount = useMemo(() => (data?.services || []).filter((s) => s.ok).length, [data]);
- const trackedDomains = useMemo(
- () => (data?.sites || []).filter((s) => s.kind !== "infra" && s.umami_website_id).map((s) => s.domain),
- [data]
+ const modalRole = useMemo(
+ () => overview.find((s) => s.domain === domain)?.role || data?.sites?.find((s) => s.domain === domain)?.role,
+ [overview, data, domain]
);
const agoSec = lastOkAt ? Math.max(0, Math.floor((now - lastOkAt) / 1000)) : null;
@@ -321,8 +540,6 @@ export default function OpsPage() {
}
}
- const st = detail?.stats;
-
return (
@@ -395,7 +612,10 @@ export default function OpsPage() {
<>
-
各站点概览
+
+
各站点概览
+
点击卡片弹出访客详情(页面 / 来源 / 地区 / 设备等)
+
{RANGES.map((r) => (