diff --git a/src/AnalyticsPage.tsx b/src/AnalyticsPage.tsx index 20eebb8..5d43d98 100644 --- a/src/AnalyticsPage.tsx +++ b/src/AnalyticsPage.tsx @@ -1,5 +1,5 @@ import { useState } from "react"; -import { trendRows, downloadCsv, type TrendMetric } from "./analytics-data"; +import { trendRows, type TrendMetric } from "./analytics-data"; import { Button } from "@/components/ui/button"; import { Select } from "@/components/ui/select"; import { Input } from "@/components/ui/input"; @@ -17,7 +17,6 @@ import { Badge } from "@/components/ui/badge"; import { Card, CardContent, - CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; @@ -34,6 +33,7 @@ function percentage(value: number | null) { function day(value: string) { return new Intl.DateTimeFormat("de-DE", { + timeZone: "UTC", day: "2-digit", month: "short", }).format(new Date(value)); @@ -161,24 +161,9 @@ function GrowthChart({ analytics }: { analytics: Analytics }) {
Verlauf · UTC -
- - -
+
( {row.module} - + {number(row.launches)} - + {number(row.unique_users)} - + {percentage(total ? (row.launches / total) * 100 : 0)} @@ -427,13 +403,204 @@ function Anomalies({ analytics }: { analytics: Analytics }) { ); } +type Journey = NonNullable; + +function NewUserChart({ dates }: { dates: Journey["days"] }) { + const [mode, setMode] = useState<"volume" | "rates">("volume"); + const [selected, setSelected] = useState(""); + const current = dates.find((row) => row.day === selected) ?? dates.at(-1); + const maximum = Math.max(1, ...dates.map((row) => row.new_users)); + const volume = mode === "volume"; + const top = volume ? maximum : 100; + const scale = [top, top / 2, 0]; + return ( +
+
+

Pro Tag

+ +
+
+ {[["bg-primary-500", "Wieder aktiv"], + [volume ? "bg-surface-300 dark:bg-surface-700" : "bg-violet-500", + volume ? "Ohne Rückkehr" : "Modul gestartet"], + ["bg-amber-400", "Beobachtung läuft"]].map(([color, label]) => ( + + {label} + + ))} +
+
+ ); +} + +function WeekComparison({ dates }: { dates: Journey["days"] }) { + // The latest eight dates include today and seven cohorts still under observation. + const recent = dates.slice(-15, -8); + const previous = dates.slice(-22, -15); + if (recent.length !== 7 || previous.length !== 7) return null; + const windows = [previous, recent].map((week) => ({ + label: `${day(week[0].day)} – ${day(week[6].day)}`, + eligible: week.reduce((sum, row) => sum + row.eligible, 0), + returned: week.reduce((sum, row) => sum + row.returned, 0), + opened_module: week.reduce((sum, row) => sum + row.opened_module, 0), + })); + return ( +
+

Wochenvergleich

+
+ {([["returned", "Wieder aktiv"], ["opened_module", "Modul gestartet"]] as const).map(([metric, label]) => ( +
+

{label}

+ {windows.map((window, index) => { + const rate = window.eligible ? 100 * window[metric] / window.eligible : null; + return ( +
+ {window.label} + + ); + })} +
+ ))} +
+
+ ); +} + +function NewUserJourney({ journey, analytics }: { journey: Journey; analytics: Analytics }) { + const outcomes = new Map(journey.days.map((row) => [row.day, row])); + const dates = analytics.login_series.map(({ day }) => + outcomes.get(day) ?? { day, new_users: 0, eligible: 0, returned: 0, opened_module: 0 }, + ); + const totals = dates.reduce( + (sum, row) => ({ + eligible: sum.eligible + row.eligible, + returned: sum.returned + row.returned, + opened: sum.opened + row.opened_module, + }), + { eligible: 0, returned: 0, opened: 0 }, + ); + + return ( + + + Neue Konten · Erste Woche + + +
+ {([ + ["Rückkehr (Tag 1–7)", totals.returned], + ["Modulstart (Tag 0–7)", totals.opened], + ] as const).map(([label, count]) => ( +
+

{label}

+

+ {percentage(totals.eligible ? count / totals.eligible * 100 : null)} +

+

+ {totals.eligible + ? `${number(count)} von ${number(totals.eligible)} Konten` + : "Beobachtung läuft"} +

+
+ ))} +
+
+ {journey.days.length ? + :

Keine neuen Konten im Zeitraum.

} +
+

Beliebteste Module

+ {journey.modules.length ? ( +
    + {journey.modules.map((module) => ( +
  • +
    + {module.module} + {percentage(module.unique_users / totals.eligible * 100)} · {number(module.unique_users)} Konten · {number(module.launches)} Starts +
    +
  • + ))} +
+ ) :

Keine Modulstarts erfasst.

} +
+
+ {journey.days.length > 0 && } +
+
+ ); +} + function Retention({ analytics }: { analytics: Analytics }) { return ( - + - Retention · Kohorten + Rückkehr nach Erstnutzungswoche @@ -458,18 +625,17 @@ function Retention({ analytics }: { analytics: Analytics }) { {day(cohort.cohort)} - + {number(cohort.new_users)} - - {percentage(cohort.retention_1d)} - - - {percentage(cohort.retention_7d)} - - - {percentage(cohort.retention_30d)} - + {[cohort.retention_1d, cohort.retention_7d, cohort.retention_30d].map((rate, index) => ( + + + {rate !== null && + + ))} ))} @@ -561,32 +727,29 @@ export function AnalyticsPage({ {error}

)} -

- {loading - ? "Laden …" - : `${rows[0]?.day || "—"} – ${rows.at(-1)?.day || "—"} · UTC · ${new Date(analytics.generated_at).toLocaleString("de-DE")}`} -

+ {loading &&

Laden …

}
{totals.map(([label, value]) => (

{label}

-

+

{value.toLocaleString("de-DE", { maximumFractionDigits: 1 })}

))}
+ {analytics.new_user_journey && ( + + )} +
-
- - -
+ ); } diff --git a/src/api.ts b/src/api.ts index 44e2ecf..aa045ce 100644 --- a/src/api.ts +++ b/src/api.ts @@ -106,6 +106,10 @@ export type Analytics = { heatmap: Array<{ weekday: number; hour: number; events: number; unique_users: number }> module_usage: Array<{ module: string; launches: number; unique_users: number }> anomalies: Array<{ day: string; metric: string; value: number; baseline: number; direction: 'spike' | 'drop'; severity: 'medium' | 'high' }> + new_user_journey?: { + days: Array<{ day: string; new_users: number; eligible: number; returned: number; opened_module: number }> + modules: Array<{ module: string; unique_users: number; launches: number }> + } retention: Array<{ cohort: string; new_users: number; retention_1d: number | null; retention_7d: number | null; retention_30d: number | null }> definitions: { heatmap: string; modules: string; anomalies: string; retention: string } }