2026-04-15 11:07:19 +08:00

115 lines
2.5 KiB
TypeScript

export const ANALYTICS_RANGE_OPTIONS = [1, 7, 30, 90] as const;
export const TRACK_FLUSH_INTERVAL_MS = 5000;
export const TRACK_BATCH_SIZE = 12;
export type AnalyticsPlatform = "WEB" | "ANDROID";
export type JsonPrimitive = string | number | boolean | null;
export type JsonValue = JsonPrimitive | JsonValue[] | { [key: string]: JsonValue };
export interface AnalyticsSessionPayload {
sessionKey: string;
platform: AnalyticsPlatform;
domain?: string;
channel?: string;
visitorId?: string;
userId?: string;
locale?: string;
timezone?: string;
referrer?: string;
userAgent?: string;
ipAddress?: string;
appVersion?: string;
browser?: string;
browserVersion?: string;
deviceType?: string;
deviceBrand?: string;
deviceModel?: string;
osName?: string;
osVersion?: string;
screenWidth?: number;
screenHeight?: number;
}
export interface AnalyticsEventPayload {
name: string;
type: string;
pageUrl?: string;
pathname?: string;
title?: string;
referrer?: string;
elementTag?: string;
elementText?: string;
elementId?: string;
elementRole?: string;
component?: string;
value?: string;
durationMs?: number;
sequence?: number;
occurredAt?: string;
metadata?: JsonValue;
}
export interface AnalyticsBatchPayload {
session: AnalyticsSessionPayload;
events: AnalyticsEventPayload[];
}
export interface DashboardQuery {
days: number;
}
export interface DashboardStat {
label: string;
value: number;
hint: string;
}
export interface DashboardTrendPoint {
bucket: string;
total: number;
}
export interface DashboardTopItem {
label: string;
total: number;
detail?: string | null;
}
export interface DashboardRecentEvent {
id: string;
sessionKey: string;
platform: AnalyticsPlatform;
name: string;
type: string;
pathname: string | null;
component: string | null;
elementText: string | null;
occurredAt: string;
metadata: JsonValue | null;
}
export interface DashboardRecentSession {
sessionKey: string;
platform: AnalyticsPlatform;
eventCount: number;
locale: string | null;
appVersion: string | null;
deviceLabel: string;
lastSeenAt: string;
}
export interface DashboardData {
stats: DashboardStat[];
activityTrend: DashboardTrendPoint[];
topEvents: DashboardTopItem[];
topPaths: DashboardTopItem[];
recentEvents: DashboardRecentEvent[];
recentSessions: DashboardRecentSession[];
}
export interface PublicAnalyticsSnapshot {
events24h: number;
sessions24h: number;
topAction: string;
}