A whole analytics page: who's online, numbers that pick what the chart shows, the period before, and pages, sources and countries.
Installation
When to use
- A whole analytics page: who's online, numbers that pick what the chart shows, the period before, and top lists.
- Product and marketing analytics with a few headline metrics and a 7, 30 or 90 day range.
When not to use
- Ops and infrastructure metrics across many small panels: Analytics panels.
- One or two numbers on a home page: Stats cards.
Usage
Analytics overview with your own data: every prop has the sample as its default, so pass only what you have.
"use client"
import { useState } from "react"
import { AnalyticsOverview } from "@/components/dashral/blocks/analytics-overview"
export default function Analytics() {
const [site, setSite] = useState("acme.com")
const [period, setPeriod] = useState("7d")
return (
<AnalyticsOverview
sites={["acme.com", "docs.acme.com"]}
site={site}
onSiteChange={setSite}
online={18}
metrics={[
{ id: "visitors", label: "Visitors" },
{ id: "bounce", label: "Bounce rate", format: (value) => `${value}%`, aggregate: "average", invert: true },
]}
periods={[
{
value: "7d",
label: "Last 7 days",
compare: "vs. the week before",
labels: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
series: {
visitors: { now: [820, 940, 910, 1_020, 980, 640, 590], before: [760, 810, 870, 900, 950, 600, 560] },
bounce: { now: [41, 39, 40, 38, 37, 44, 45], before: [43, 42, 41, 40, 40, 46, 47] },
},
pages: [{ label: "/", value: 2_410 }, { label: "/pricing", value: 980 }],
sources: [{ label: "Google", value: 3_120 }, { label: "Direct", value: 1_460 }],
countries: [{ label: "Indonesia", value: 2_050 }, { label: "Germany", value: 940 }],
},
]}
period={period}
onPeriodChange={setPeriod}
onExport={(period) => console.log("export", site, period)}
/>
)
}API reference
AnalyticsOverview
A whole analytics page: the site, who's online, a period switch and export; four numbers that each pick what the chart shows, with their change; an area chart against the period before, read by hover or the arrow keys; then top pages, sources and countries. Every part follows the period. Your sites, metrics and each period's figures come from props; with period and onPeriodChange you load a period's figures as it's picked.
| Prop | Type | Default |
|---|---|---|
sites | string[] | sample |
site | stringThe site shown (the page keeps it without it). | — |
onSiteChange | (site: string) => void | — |
online | number | nullPeople on the site right now; null hides it. | 38 |
metrics | AnalyticsMetric[] | sample |
periods | AnalyticsPeriod[] | sample |
period | string | — |
onPeriodChange | (period: string) => void | — |
onExport | (period: string) => void | — |
type AnalyticsMetric
A number on top: how it reads, and how a period's values add up to it ("sum", or "average" for rates).
| Prop | Type | Default |
|---|---|---|
id | string | — |
label | string | — |
format | (value: number) => string | — |
aggregate | "sum" | "average" | — |
invert | boolean | — |
type BreakdownItem
| Prop | Type | Default |
|---|---|---|
label | string | — |
value | number | — |
type AnalyticsPeriod
A period on the switch: the chart's labels, what it compares with, each metric's values now and before (by id), and the breakdowns.
| Prop | Type | Default |
|---|---|---|
value | string | — |
label | string | — |
compare | string | — |
labels | string[] | — |
series | Record<string, { now: number[]; before: number[] }> | — |
pages | BreakdownItem[] | — |
sources | BreakdownItem[] | — |
countries | BreakdownItem[] | — |