- ipalKit({ searchSettings }): switches off / reshapes Site Settings → Search & AI
without `seo`; read as options.searchSettings ?? options.seo?.searchSettings.
- shouldLoadGoogle moved to a pure module (analytics/shouldLoadGoogle.ts) and
exported from @intecion/ipal-kit and /client.
- consentLog.collectionOverrides and stats.collectionOverrides (object merges
access/admin/hooks key by key, function takes over), via the new exported
applyCollectionOverride / CollectionOverride. The stats view and dashboard
chart now follow the stats-visits read access, so overrides narrow them too.
All additive; defaults unchanged. Docs: AGENT.md, ipal-reference, consent,
stats, seo, analytics, ipal-setup.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
9.3 KiB
stats
Built-in statistics in the admin panel: daily visits for the last 30 days, most viewed pages, entry pages, traffic sources, devices — and visitor history, but only for visitors who consented to analytics cookies. The data stays in the project's database; nothing goes to Google or other companies.
Two levels — and why the first needs no consent
| Without consent (every visitor) | With analytics consent (the same one as GA4) | |
|---|---|---|
| What is in the browser | nothing — no cookie, localStorage, fingerprint | cookie ipal_vid (random id, 180 days) |
| How page views are joined into a visit | hash of a random salt + IP + user agent; the salt lives only in server memory and is rotated daily — after midnight nobody (us included) can link a visit to an IP or to a visit from another day | as on the left + visitorId from the cookie |
| What the panel shows | daily chart, pages, entries, sources, devices, path within one visit | additionally this person's history across many days |
| Stored IP / user agent | no | no |
- Art. 399 of the Polish Electronic Communications Law (ePrivacy 5(3)) requires consent to store or read information on the user's device. Level 1 stores and reads nothing on the device, so the banner does not apply to it.
- GDPR still applies — the IP is processed for a moment while computing the hash. Legal basis: legitimate interest (Art. 6(1)(f)). Describe it in the privacy policy (text below).
- Level 2 without consent is illegal —
<PageStats>createsipal_vidonly after analytics consent, and the server still checks the consent cookie (with the current Policy version) before it storesvisitorId. Do not work around this.
This is not legal advice — for an unusual project (sensitive data, children) consult the client's lawyer.
Config
ipalKit({
// …
stats: true,
// or:
stats: {
retentionDays: 90, // how many days visits are kept (default 90; the chart shows 30)
timeZone: 'Europe/Warsaw', // where a "day" starts (default Europe/Warsaw)
dashboard: true, // chart on the panel dashboard (default true)
},
})
Option (StatsOptions) |
Default | Description |
|---|---|---|
retentionDays |
90 |
older visits (by lastAt) are deleted |
timeZone |
'Europe/Warsaw' |
day boundary (day field, salt rotation, charts) |
dashboard |
true |
false removes only StatsWidget from the dashboard — the view and the nav link stay |
collectionOverrides |
none | changes stats-visits: an object merges access / admin / hooks key by key (your keys win), a function (collection) => collection takes over (keep the slug). Its access.read also decides who sees the stats view and the dashboard chart |
Adds:
- the
stats-visitscollection (group Statistics, read and delete: admin;create/updatevia API blocked — written only by the endpoint withoverrideAccess), POST /api/ipal/hit,- the
<adminRoute>/statsview (default/admin/stats; it usesipalKit({ adminRoute }), notroutes.adminset by hand in the config) + a nav link (StatsNavLink), - a 30-day chart on the dashboard (
StatsWidget), STATS_SLUG('stats-visits') from@intecion/ipal-kit— for your own queries.
After enabling: pnpm payload generate:importmap (components @intecion/ipal-kit/admin#StatsView,
#StatsWidget, #StatsNavLink) and a database migration (Postgres: pnpm payload migrate:create).
Front
With SiteProviders:
<SiteProviders shell={shell} logEndpoint="/api/ipal/consent" stats={{ locale }}>
Or by hand — inside ConsentProvider:
import { PageStats } from '@intecion/ipal-kit/client'
<PageStats locale={locale} /> // endpoint defaults to '/api/ipal/hit'
<PageStats> sends one beacon per page view (also on Next client-side navigation; sendBeacon,
fallback fetch with keepalive). It renders nothing. Props (PageStatsProps): endpoint
(default '/api/ipal/hit'), locale.
POST /api/ipal/hit
Body: { p: path, r?: referrer, l?: locale, v?: visitorId }. Always answers 204 (also on an
error, a rejection and when the limit of 60 requests/min per IP is exceeded — scope stats). v is
stored only when the request's consent cookie has analytics: true under the current Policy version
(version read from Cookie Settings, cached 1 min). Path: must start with /, max 300 characters;
visit: max 200 page views. locale is stored when it matches xx / xx-XX.
VISITOR_COOKIE ('ipal_vid') from /client — the cookie name, e.g. for your own cookie table.
CSP: the endpoint is on the same domain — connect-src 'self' is enough.
What we do not count
- logged-in panel users (an editor viewing the site does not inflate the stats),
- bots (Googlebot, link previews, Lighthouse, curl, headless),
- Next prefetch (
sec-purpose: prefetch), - a reload of the same page within 10 s.
We store only the path: the query string and #hash are cut off (they can contain an e-mail, a token,
a search phrase). Referrer — only the domain name. Country — only from the Cloudflare cf-ipcountry
header, if present.
Visit
A sequence of page views with gaps under 30 minutes, within one day. A server restart or several instances (each has its own salt) can split an ongoing visit in two — irrelevant for statistics. Do not store the salt in the database to "fix" this: then yesterday's hashes could be reversed to IPs.
Visits older than retentionDays are deleted automatically — at most once a day per server process,
on a page view, with one db.deleteMany query in the background (the page view does not wait for
the cleanup; an error goes to the log and the cleanup is retried on the next page view). The salt
changes when day changes in the timeZone zone.
Visitor rights (GDPR)
- Withdrawing consent —
useConsentdeletesipal_vid(it is inDEFAULT_COOKIE_MAP.analytics); further page views are anonymous. - Deleting data — the visitor gives the id from the
ipal_vidcookie (DevTools → Application → Cookies). In the panel: Statistics → Visits, filtervisitorId= id → select all → Delete. The/admin/stats?visitor=<id>view shows the same as a history. - Anonymous visits cannot be linked to a person — there is nothing to hand over or delete on request.
For the privacy policy and the cookie table
Add a row in Cookie Settings → Cookies (panel):
| Name | Provider | Category | Purpose | Duration |
|---|---|---|---|---|
ipal_vid |
this site | analytics | Recognising a returning visitor in the site statistics | 180 days |
Privacy policy text — adjust the controller name and the retention period, paste the version for each language of the site:
Visit statistics. We count visits to this site with our own tool, without third parties. Without your
consent we store nothing on your device: page views are joined into a visit with a one-day, irreversible
hash of the IP address and the browser type; the IP address itself is not stored, and the hash becomes
meaningless after a day. We record the pages visited, the time, the referring domain, the device type
(desktop / mobile / tablet) and the language. The legal basis is our legitimate interest (Art. 6(1)(f)
GDPR) — knowing how the site is used. If you accept analytics cookies, we set the `ipal_vid` cookie with
a random identifier so that your later visits appear as one history (legal basis: consent, Art. 6(1)(a)
GDPR; you can withdraw it in the cookie settings). We keep the data for 90 days.
Polish version (for a pl site):
Statystyki odwiedzin. Liczymy odwiedziny strony własnym narzędziem, bez udziału podmiotów
trzecich. Bez Twojej zgody nie zapisujemy niczego na Twoim urządzeniu: kolejne odsłony łączymy w
wizytę za pomocą jednodniowego, nieodwracalnego skrótu adresu IP i typu przeglądarki; samego adresu
IP nie przechowujemy, a skrót traci znaczenie po upływie doby. Zapisujemy odwiedzone podstrony,
czas, domenę strony odsyłającej, rodzaj urządzenia (komputer / telefon / tablet) i język.
Podstawą jest nasz prawnie uzasadniony interes (art. 6 ust. 1 lit. f RODO) — wiedza, jak
korzystacie ze strony. Jeśli zgodzisz się na cookies analityczne, zapiszemy cookie `ipal_vid` z
losowym identyfikatorem, dzięki któremu zobaczymy Twoje kolejne wizyty jako jedną historię
(podstawa: zgoda, art. 6 ust. 1 lit. a RODO; możesz ją wycofać w ustawieniach cookies). Dane
przechowujemy przez 90 dni.
Turn off, override, extend
- Turn off: without the
statsoption nothing is added;stats: { dashboard: false }hides only the dashboard chart; without<PageStats>(or withSiteProviders stats=false) nothing is sent. - Override:
retentionDays,timeZone,collectionOverrides(e.g.{ access: { read: ({ req }) => req.user?.email === '[email protected]' } }in a project without roles);<PageStats endpoint>for your own endpoint path. The counting rules (bots, prefetch, 30 min, 10 s) currently cannot be changed with an option. - Extend:
STATS_SLUG+ the typesStatsOptions/StatsVisit/StatsPage(from@intecion/ipal-kit) for your own queries and reports (Local API);StatsView/StatsWidgetfrom/admincan be wired by hand. The collection and endpoint builders are currently not publicly exported.