- 新增 AdminSessionRecover:后台离线/后端重启时自动重试恢复会话,明确失效才回跳登录 - 认证 cookie 契约调整(SameSite=Lax 与刷新轮转适配),路由与守卫适配 - 访问来源统计查询优化与测试、管理端 analytics sources 页面适配 - 移动端布局修正:覆盖 body min-h-screen 避免内容区高度异常
38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
"use client";
|
||
|
||
import { Suspense, useEffect, useRef } from "react";
|
||
import { usePathname, useSearchParams } from "next/navigation";
|
||
import { apiTelemetryPageView } from "@/lib/api";
|
||
|
||
function BeaconInner() {
|
||
const pathname = usePathname();
|
||
const search = useSearchParams().toString();
|
||
const lastRef = useRef<{ path: string; at: number }>({ path: "", at: 0 });
|
||
|
||
useEffect(() => {
|
||
if (!pathname || pathname === "/admin" || pathname.startsWith("/admin/")) return;
|
||
// 完整 URL(含 query):query 变化也上报,站内搜索 /?q=… 才能被记录
|
||
const full = pathname + (search ? `?${search}` : "");
|
||
const now = Date.now();
|
||
if (lastRef.current.path === full && now - lastRef.current.at < 30_000) return;
|
||
lastRef.current = { path: full, at: now };
|
||
// 来源页,供后台来源分析
|
||
const ref = typeof document !== "undefined" ? document.referrer : "";
|
||
void apiTelemetryPageView(full, ref);
|
||
}, [pathname, search]);
|
||
|
||
return null;
|
||
}
|
||
|
||
/**
|
||
* 公开站页面访问埋点:同 URL 30s 内合并;跳过 /admin。
|
||
* useSearchParams 需 Suspense 边界(与 FooterTiming 同模式)。
|
||
*/
|
||
export default function VisitBeacon() {
|
||
return (
|
||
<Suspense fallback={null}>
|
||
<BeaconInner />
|
||
</Suspense>
|
||
);
|
||
}
|