import { Activity, BadgeDollarSign, BrainCircuit, ChartNoAxesCombined, Gauge, Repeat2, Sparkles, Target, Users, } from "lucide-react"; import { useCallback, useEffect, useState } from "react"; import { adminApi } from "../../api/client"; import type { AnalyticsRate, ProductAnalyticsOverview } from "../../api/types"; import { CohortHeatmap } from "../../components/charts/cohort-heatmap"; import { ComparisonBarChart } from "../../components/charts/comparison-bar-chart"; import { FunnelChart } from "../../components/charts/funnel-chart"; import { Card, ErrorState, LoadingState, PageHeader, StatCard } from "../../components/primitives"; import { RangeControl } from "../../components/range-control"; import { formatNumber } from "../../lib/format"; export function AnalyticsPage() { const [range, setRange] = useState("30d"); const [data, setData] = useState(); const [error, setError] = useState(); const load = useCallback(async () => { setError(undefined); try { setData(await adminApi.productAnalytics(range)); } catch (requestError) { setError(requestError); } }, [range]); useEffect(() => { void load(); }, [load]); if (error) return void load()} />; if (!data) return ; const weeklyGrowth = data.northStar.weekOverWeekPercent; return (
} />
{data.aiFeatures.length === 0 ? (

等待客户端接入事件后显示

) : ( right.successes - left.successes) .map((item) => ({ id: `${item.feature}-${item.executionMode}`, label: featureLabel(item.feature), value: item.successes, secondaryValue: item.users, hint: executionModeLabel(item.executionMode), }))} primaryLabel="成功次数" secondaryLabel="成功用户" primaryTone="violet" secondaryTone="success" /> )}
`${value.toFixed(1)}%`} /> `${value.toFixed(1)}%`} />
({ label: channelLabel(channel.channel), value: channel.installations, secondaryValue: channel.activated, hint: `激活率 ${rateLabel(channel.activationRate)}`, }))} primaryLabel="新增安装" secondaryLabel="24 小时激活" emptyText="暂无渠道归因数据" />
); } function SectionHeader({ title, description, icon: Icon, }: { title: string; description: string; icon: typeof Activity; }) { return (

{title}

{description}

); } function MetricRows({ rows }: { rows: Array<[string, string]> }) { return (
{rows.map(([label, value]) => (
{label}
{value}
))}
); } function rateLabel(rate?: AnalyticsRate): string { return rate?.percent == null ? "—" : `${rate.percent.toFixed(1)}%`; } function optionalPercent(value?: number): string { return value == null ? "—" : `${value.toFixed(1)}%`; } function optionalDecimal(value?: number): string { return value == null ? "—" : value.toFixed(2); } function optionalNumber(value?: number): string { return value == null ? "—" : formatNumber(Math.round(value)); } function optionalMinutes(value?: number): string { return value == null ? "—" : `${Math.round(value)} 分钟`; } function signedPercent(value: number): string { return `${value >= 0 ? "+" : ""}${value.toFixed(1)}%`; } function latestMatureRetention( data: ProductAnalyticsOverview, key: "d1" | "d7" | "d30", ): string { return rateLabel(data.retention.find((cohort) => cohort[key]?.percent != null)?.[key]); } function channelLabel(channel: string): string { return { APP_STORE_ORGANIC: "App Store 自然量", REFERRAL: "用户邀请", SOCIAL_CONTENT: "社交 / 内容", UNKNOWN: "未知来源", }[channel] ?? channel; } function featureLabel(feature: string): string { return { TRANSCRIPTION: "语音转写", POLISH: "文字润色", AI_ASSISTANT: "AI 助手", AGENT: "Agent", HOTWORD: "快捷指令", OTHER: "其他", }[feature] ?? feature; } function executionModeLabel(mode: string): string { return { MANAGED: "托管", LOCAL: "本地", BYOK: "BYOK", }[mode] ?? mode; }