"use client" import { useState, useEffect } from "react" import { TrendingUp, Users, Monitor, Tag } from "lucide-react" import ReactEChartsCore from "echarts-for-react/lib/core" import * as echarts from "echarts/core" import { LineChart, BarChart } from "echarts/charts" import { GridComponent, TooltipComponent, LegendComponent, } from "echarts/components" import { CanvasRenderer } from "echarts/renderers" echarts.use([LineChart, BarChart, GridComponent, TooltipComponent, LegendComponent, CanvasRenderer]) interface AnalyticsData { benchmarkTimeline: Array<{ day: string; count: number }> userTimeline: Array<{ day: string; count: number }> deviceDistribution: Array<{ hardwareSlug: string; hardwareName: string; count: number }> genrePopularity: Array<{ genre: string; count: number }> commentTimeline: Array<{ day: string; count: number }> } export function AnalyticsClient() { const [data, setData] = useState(null) const [loading, setLoading] = useState(true) useEffect(() => { fetch("/api/admin/analytics/overview") .then((res) => res.json()) .then((d) => { setData(d); setLoading(false) }) .catch(() => setLoading(false)) }, []) if (loading) { return
} if (!data) { return
Failed to load analytics
} const benchmarkOption = { tooltip: { trigger: "axis" as const }, xAxis: { type: "category" as const, data: data.benchmarkTimeline.map((d) => d.day), axisLabel: { fontSize: 10 } }, yAxis: { type: "value" as const }, series: [{ name: "Benchmarks", type: "line", data: data.benchmarkTimeline.map((d) => d.count), smooth: true, itemStyle: { color: "#eb3779" } }], grid: { left: 40, right: 16, top: 16, bottom: 24 }, } const userOption = { tooltip: { trigger: "axis" as const }, xAxis: { type: "category" as const, data: data.userTimeline.map((d) => d.day), axisLabel: { fontSize: 10 } }, yAxis: { type: "value" as const }, series: [{ name: "Registrations", type: "line", data: data.userTimeline.map((d) => d.count), smooth: true, itemStyle: { color: "#a78bfa" }, areaStyle: { color: "rgba(167,139,250,0.1)" } }], grid: { left: 40, right: 16, top: 16, bottom: 24 }, } const deviceOption = { tooltip: { trigger: "axis" as const }, xAxis: { type: "category" as const, data: data.deviceDistribution.map((d) => d.hardwareName), axisLabel: { fontSize: 10 } }, yAxis: { type: "value" as const }, series: [{ name: "Benchmarks", type: "bar", data: data.deviceDistribution.map((d) => d.count), itemStyle: { color: "#fb793c" } }], grid: { left: 40, right: 16, top: 16, bottom: 24 }, } const genreOption = { tooltip: { trigger: "axis" as const }, xAxis: { type: "category" as const, data: data.genrePopularity.map((d) => d.genre), axisLabel: { fontSize: 10, rotate: 30 } }, yAxis: { type: "value" as const }, series: [{ name: "Benchmarks", type: "bar", data: data.genrePopularity.map((d) => d.count), itemStyle: { color: "#22c55e" } }], grid: { left: 40, right: 16, top: 16, bottom: 60 }, } return (

Analytics

90-day trends and distributions

{/* Benchmark Submissions Over Time */}

Benchmark Submissions (90d)

{/* User Registrations Over Time */}

User Registrations (90d)

{/* Device Distribution + Genre Popularity (side by side) */}

Device Distribution

Genre Popularity

) }