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,122 @@
|
||||
'use client'
|
||||
import { useConfig, useDocumentInfo, useFormFields, useLocale } from '@payloadcms/ui'
|
||||
import { useEffect, useState } from 'react'
|
||||
|
||||
export type MetaDescriptionCheckProps = {
|
||||
/** An empty description is filled from the page content on save (autoFill). */
|
||||
autoFill?: boolean
|
||||
/** SiteSettings global slug. */
|
||||
settingsSlug?: string
|
||||
/** Field on SiteSettings holding the site-wide fallback description. */
|
||||
siteDescriptionField?: string
|
||||
/** Field shown as the name of the page that has the same description. */
|
||||
titleField?: string
|
||||
}
|
||||
|
||||
type Warning = { text: string; tone: 'info' | 'warn' }
|
||||
|
||||
const norm = (v: unknown) => (typeof v === 'string' ? v.trim().replace(/\s+/g, ' ') : '')
|
||||
|
||||
/**
|
||||
* Hint under the meta description in the SEO tab. Google ignores a description
|
||||
* it sees on many pages and quotes page text instead (usually the footer), so
|
||||
* this flags a description that matches the site-wide fallback or another
|
||||
* document in the collection. Advisory only — saving is never blocked. Length
|
||||
* is already shown by plugin-seo's own counter.
|
||||
*/
|
||||
export function MetaDescriptionCheck({
|
||||
autoFill = true,
|
||||
settingsSlug = 'site-settings',
|
||||
siteDescriptionField = 'siteDescription',
|
||||
titleField = 'title',
|
||||
}: MetaDescriptionCheckProps) {
|
||||
const description = norm(useFormFields(([f]) => f['meta.description']?.value))
|
||||
const { id, collectionSlug } = useDocumentInfo()
|
||||
const { code: locale } = useLocale()
|
||||
const {
|
||||
config: {
|
||||
routes: { api },
|
||||
serverURL,
|
||||
},
|
||||
} = useConfig()
|
||||
const [warning, setWarning] = useState<null | Warning>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!description) {
|
||||
setWarning(
|
||||
autoFill
|
||||
? { text: 'Empty — on save it is filled from this page’s content. Writing your own is better.', tone: 'info' }
|
||||
: { text: 'Empty — the page gets the site-wide description, the same as every other page.', tone: 'warn' },
|
||||
)
|
||||
return
|
||||
}
|
||||
if (!collectionSlug) {return}
|
||||
|
||||
const controller = new AbortController()
|
||||
const base = `${serverURL ?? ''}${api}`
|
||||
const get = async (url: string) => {
|
||||
const res = await fetch(url, { credentials: 'include', signal: controller.signal })
|
||||
return res.ok ? ((await res.json()) as Record<string, unknown>) : null
|
||||
}
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
void (async () => {
|
||||
try {
|
||||
const settings = await get(`${base}/globals/${settingsSlug}?depth=0&locale=${locale}`)
|
||||
if (settings && norm(settings[siteDescriptionField]) === description) {
|
||||
setWarning({
|
||||
text: 'Same as the site-wide description. Google ignores a description repeated across pages — write one about this page.',
|
||||
tone: 'warn',
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const query = new URLSearchParams({
|
||||
depth: '0',
|
||||
limit: '1',
|
||||
locale,
|
||||
'where[meta.description][equals]': description,
|
||||
})
|
||||
if (id !== undefined && id !== null) {query.set('where[id][not_equals]', String(id))}
|
||||
const found = await get(`${base}/${collectionSlug}?${query}`)
|
||||
const twin = (found?.docs as Record<string, unknown>[] | undefined)?.[0]
|
||||
if (twin) {
|
||||
const name = norm(twin[titleField]) || String(twin.id)
|
||||
setWarning({
|
||||
text: `Same description as “${name}”. Google ignores a description repeated across pages — make each one unique.`,
|
||||
tone: 'warn',
|
||||
})
|
||||
return
|
||||
}
|
||||
setWarning(null)
|
||||
} catch {
|
||||
// aborted or offline — a hint is not worth an error
|
||||
}
|
||||
})()
|
||||
}, 600)
|
||||
|
||||
return () => {
|
||||
clearTimeout(timer)
|
||||
controller.abort()
|
||||
}
|
||||
}, [api, autoFill, collectionSlug, description, id, locale, serverURL, settingsSlug, siteDescriptionField, titleField])
|
||||
|
||||
if (!warning) {return null}
|
||||
|
||||
return (
|
||||
<div
|
||||
role="status"
|
||||
style={{
|
||||
background:
|
||||
warning.tone === 'warn' ? 'var(--theme-warning-50, rgba(255, 178, 36, 0.1))' : 'var(--theme-elevation-50)',
|
||||
border: `1px solid ${warning.tone === 'warn' ? 'var(--theme-warning-400, #ffb224)' : 'var(--theme-elevation-150)'}`,
|
||||
borderRadius: 4,
|
||||
fontSize: '0.85rem',
|
||||
marginBottom: '1.5rem',
|
||||
padding: '0.6rem 0.9rem',
|
||||
}}
|
||||
>
|
||||
{warning.text}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user