Built-in statistics (cookieless, consent-gated visitor history); per-page meta descriptions, NoSnippet
Stats: ipalKit({ stats: true }) adds the stats-visits collection, POST /api/ipal/hit, the
/admin/stats view (30-day visits chart, top/entry pages, referrers, devices), a dashboard card
and a nav link. <PageStats> (or <SiteProviders stats>) sends one beacon per page view. Without
consent nothing is stored on the device and no IP is kept: page views are joined by a hash with
an in-memory salt replaced daily. With analytics consent an ipal_vid cookie links visits across
days (server re-checks the consent cookie and policy version; withdrawal deletes the cookie).
Bots, logged-in panel users and prefetches aren't counted. Retention 90 days.
@payloadcms/next added to peerDependencies (DefaultTemplate). Docs: stats.md with privacy text.
Also in this release: meta.description auto-filled from page blocks, <NoSnippet>,
MetaDescriptionCheck in the SEO tab, data-nosnippet on banner/language switcher, GA4 CSP
wildcards, consent version passed to Analytics' default consent.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
305c564d13
commit
4ec27d9ef0
@@ -0,0 +1,42 @@
|
||||
import type { Payload, PayloadRequest } from 'payload'
|
||||
|
||||
import { isAdmin } from '../../access/predicates.js'
|
||||
import { loadStats } from './loadStats.js'
|
||||
import { STATS_CSS, VisitsChart } from './VisitsChart.js'
|
||||
|
||||
type Props = {
|
||||
adminRoute?: string
|
||||
/** Injected by Payload into admin server components. */
|
||||
payload?: Payload
|
||||
req?: PayloadRequest
|
||||
timeZone?: string
|
||||
user?: unknown
|
||||
}
|
||||
|
||||
/**
|
||||
* Dashboard card (admin.components.beforeDashboard): visits per day for the
|
||||
* last 30 days with a link to the full view. Admins only; renders nothing on
|
||||
* any error (DB not ready, collection missing).
|
||||
*/
|
||||
export async function StatsWidget({ adminRoute = '/admin', payload, req, timeZone = 'Europe/Warsaw', user }: Props) {
|
||||
if (!payload || !isAdmin((req?.user ?? user) as never)) {return null}
|
||||
let stats
|
||||
try {
|
||||
stats = await loadStats(payload, { timeZone })
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
return (
|
||||
<section className="ipal-stats" style={{ marginBottom: '2rem' }}>
|
||||
<style>{STATS_CSS}</style>
|
||||
<h2 style={{ marginBottom: '0.25rem' }}>Visits per day</h2>
|
||||
<p style={{ color: 'var(--theme-elevation-500)', margin: '0 0 0.75rem' }}>
|
||||
Last 30 days: {stats.totals.visits.toLocaleString('en-US')} visits, {stats.totals.views.toLocaleString('en-US')} page views ·{' '}
|
||||
<a href={`${adminRoute.replace(/\/$/, '')}/stats`}>All statistics →</a>
|
||||
</p>
|
||||
<VisitsChart days={stats.days} />
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default StatsWidget
|
||||
Reference in New Issue
Block a user