import type { AdminViewServerProps } from 'payload'
import { DefaultTemplate } from '@payloadcms/next/templates'
import { Gutter } from '@payloadcms/ui'
import type { StatsVisit } from '../collection.js'
import { isAdmin } from '../../access/predicates.js'
import { VISITOR_ID_PATTERN } from '../parse.js'
import { loadRecentVisitors, loadStats, loadVisitor } from './loadStats.js'
import { STATS_CSS, VisitsChart } from './VisitsChart.js'
type Props = { adminRoute?: string; timeZone?: string } & AdminViewServerProps
const fmt = (n: number) => n.toLocaleString('en-US')
const when = (iso: string, timeZone: string) =>
new Intl.DateTimeFormat('en-GB', { dateStyle: 'medium', timeStyle: 'short', timeZone }).format(new Date(iso))
function TopList({ rows, title, unit }: { rows: [string, number][]; title: string; unit: string }) {
return (
No data yet.{title}
{rows.length ? (
) : (
{rows.map(([key, count]) => (
{title}
{unit}
))}
{key}{fmt(count)}
{visitorId}{visits.length} visit{visits.length === 1 ? '' : 's'} recorded with analytics consent. To erase this visitor’s data, filter Statistics → Visits by this visitor id and delete the results.
{visits.map((v) => ({p.p} {when(p.t, timeZone).split(', ').pop()}
Statistics are available to administrators only.
} else if (visitorId) { content =Last 30 days. Counted without cookies, so no consent is needed; no IP addresses are stored. Visitors who accept analytics cookies also get a history across days.
| Visitor | Last seen |
|---|---|
{v.visitorId} |
{when(v.lastAt, timeZone)} |
No visitor has accepted analytics cookies yet.
)}