feat(usage): 使用统计纳入未登录访客 — 任意工具页打开即上报(router afterEach+localStorage 10min去重+beacon), 后台总次数显示其中未登录N次+用户排行新增未登录访客行+工具名回退目录名

This commit is contained in:
3970260761 committed 2026-11-12 11:35:38 +08:00
1 parent 15d21235cd
commit cd4b324740
4 files changed
+69 -5

No files matched your search

+35
View File
@@ -238,3 +238,38 @@ export async function activateCard(cardKey: string, contactQq: string, replace =
licenseState.activating = false;
}
}
// ---- 工具使用统计上报:任何访客(含未登录)打开工具页即计一次 ----
// 同一工具 10 分钟内只上报一次(防刷新刷量),服务端还会再做一层去重与限流。
const USAGE_THROTTLE_MS = 10 * 60 * 1000;
export function reportToolUsage(path: string): void {
try {
const tool = String(path || '').replace(/^\/+/, '').slice(0, 64);
if (!tool) {
return;
}
const key = `it-tools-usage:${tool}`;
const last = Number(localStorage.getItem(key) || 0);
if (Date.now() - last < USAGE_THROTTLE_MS) {
return;
}
localStorage.setItem(key, String(Date.now()));
let machine = '';
try {
machine = getMachineId();
}
catch {
machine = '';
}
fetch('/relay/usage', {
method: 'POST',
keepalive: true,
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ machine_id: machine, tool }),
}).catch(() => {});
}
catch {
// 统计失败绝不影响功能
}
}