Merge main (security-perf + SEO) into docs; finish English docs and agent guide
- Resolve conflicts in analytics, consent, content, i18n, mcp and stats, keeping the docs fixes and the new code behaviour, verified against src - Translate the remaining 14 module pages, ipal-seo-check skill and script - Integrate the security-perf and SEO agent-guide text: getRobots, isPathVisible, Search & AI (DNS verification first, meta fields optional), sitemap index/cache/503, consentMode basic/advanced, policyVersion, globalOverrides, revalidatePath / buildGlobalRevalidateHook, authAccess, firstUserAdmin, allowCollectionMismatch, unknown-IP rate limit; stale claims fixed across AGENT.md, skills, frontend, developer guide, vibe - docsConsistency: pending list removed (all docs English); relative links now also check #anchors Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
+112
-92
@@ -1,29 +1,29 @@
|
||||
# stats
|
||||
|
||||
Wbudowane statystyki w panelu: **wizyty dziennie z ostatnich 30 dni**, najczęściej
|
||||
oglądane strony, strony wejścia, źródła ruchu, urządzenia — oraz **historia
|
||||
odwiedzającego**, ale tylko dla tych, którzy zgodzili się na cookies analityczne.
|
||||
Dane zostają w bazie projektu; nic nie idzie do Google ani innych firm.
|
||||
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.
|
||||
|
||||
## Dwa poziomy — i dlaczego pierwszy nie wymaga zgody
|
||||
## Two levels — and why the first needs no consent
|
||||
|
||||
| | Bez zgody (każdy odwiedzający) | Ze zgodą **analytics** (ta sama co GA4) |
|
||||
| | Without consent (every visitor) | With **analytics** consent (the same one as GA4) |
|
||||
|---|---|---|
|
||||
| Co w przeglądarce | **nic** — żadnego cookie, localStorage, fingerprintu | cookie `ipal_vid` (losowe id, 180 dni) |
|
||||
| Jak łączymy odsłony w wizytę | hash z losowej soli + IP + user agent; sól jest tylko w pamięci serwera i **wymieniana codziennie** — po północy nikt (także my) nie powiąże wizyty z IP ani z wizytą z innego dnia | jak obok + `visitorId` z cookie |
|
||||
| Co widać w panelu | wykres dzienny, strony, wejścia, źródła, urządzenia, ścieżka w ramach jednej wizyty | dodatkowo **historia tej osoby przez wiele dni** |
|
||||
| Zapisane IP / user agent | **nie** | **nie** |
|
||||
| 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 Prawa komunikacji elektronicznej (ePrivacy 5(3))** wymaga zgody na zapis lub odczyt
|
||||
informacji z urządzenia użytkownika. Poziom 1 niczego na urządzeniu nie zapisuje ani nie czyta,
|
||||
więc baner go nie dotyczy.
|
||||
- **RODO dalej obowiązuje** — IP jest przetwarzane przez chwilę przy liczeniu hasha. Podstawa: prawnie
|
||||
uzasadniony interes (art. 6 ust. 1 lit. f). **Trzeba to opisać w polityce prywatności** (tekst niżej).
|
||||
- **Poziom 2 bez zgody jest nielegalny** — `ipal_vid` tworzy `<PageStats>` dopiero po zgodzie na
|
||||
analytics, a serwer i tak sprawdza cookie zgody (z aktualną *Policy version*) zanim zapisze
|
||||
`visitorId`. Nie obchodź tego.
|
||||
- **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>` creates `ipal_vid` only after analytics
|
||||
consent, and the server still checks the consent cookie (with the current *Policy version*) before
|
||||
it stores `visitorId`. Do not work around this.
|
||||
|
||||
To nie jest porada prawna — przy nietypowym projekcie (dane wrażliwe, dzieci) skonsultuj z prawnikiem klienta.
|
||||
This is not legal advice — for an unusual project (sensitive data, children) consult the client's lawyer.
|
||||
|
||||
## Config
|
||||
|
||||
@@ -31,119 +31,139 @@ To nie jest porada prawna — przy nietypowym projekcie (dane wrażliwe, dzieci)
|
||||
ipalKit({
|
||||
// …
|
||||
stats: true,
|
||||
// albo:
|
||||
// or:
|
||||
stats: {
|
||||
retentionDays: 90, // ile dni trzymamy wizyty (domyślnie 90; wykres pokazuje 30)
|
||||
timeZone: 'Europe/Warsaw', // gdzie zaczyna się „dzień” (domyślnie Europe/Warsaw)
|
||||
dashboard: true, // wykres na dashboardzie panelu (domyślnie true)
|
||||
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)
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
| Opcja (`StatsOptions`) | Domyślnie | Opis |
|
||||
| Option (`StatsOptions`) | Default | Description |
|
||||
|---|---|---|
|
||||
| `retentionDays` | `90` | wizyty starsze (wg `lastAt`) są usuwane |
|
||||
| `timeZone` | `'Europe/Warsaw'` | granica dnia (pole `day`, rotacja soli, wykresy) |
|
||||
| `dashboard` | `true` | `false` usuwa tylko `StatsWidget` z dashboardu — widok i link w nawigacji zostają |
|
||||
| `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 |
|
||||
|
||||
Dodaje:
|
||||
- kolekcję `stats-visits` (grupa *Statistics*, odczyt i usuwanie: admin; `create`/`update` przez API
|
||||
zablokowane — zapis tylko endpointem z `overrideAccess`),
|
||||
Adds:
|
||||
- the `stats-visits` collection (group *Statistics*, read and delete: admin; `create`/`update` via API
|
||||
blocked — written only by the endpoint with `overrideAccess`),
|
||||
- `POST /api/ipal/hit`,
|
||||
- widok **`<adminRoute>/stats`** (domyślnie `/admin/stats`; bierze `ipalKit({ adminRoute })`, nie
|
||||
`routes.admin` ustawione ręcznie w configu) + link w nawigacji (`StatsNavLink`),
|
||||
- wykres 30 dni na dashboardzie (`StatsWidget`),
|
||||
- `STATS_SLUG` (`'stats-visits'`) z `@intecion/ipal-kit` — do własnych zapytań.
|
||||
- the **`<adminRoute>/stats`** view (default `/admin/stats`; it uses `ipalKit({ adminRoute })`, not
|
||||
`routes.admin` set 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.
|
||||
|
||||
Po włączeniu: `pnpm payload generate:importmap` (komponenty `@intecion/ipal-kit/admin#StatsView`,
|
||||
`#StatsWidget`, `#StatsNavLink`) i migracja bazy (Postgres: `pnpm payload migrate:create`).
|
||||
After enabling: `pnpm payload generate:importmap` (components `@intecion/ipal-kit/admin#StatsView`,
|
||||
`#StatsWidget`, `#StatsNavLink`) and a database migration (Postgres: `pnpm payload migrate:create`).
|
||||
|
||||
## Front
|
||||
|
||||
Z `SiteProviders`:
|
||||
With `SiteProviders`:
|
||||
|
||||
```tsx
|
||||
<SiteProviders shell={shell} logEndpoint="/api/ipal/consent" stats={{ locale }}>
|
||||
```
|
||||
|
||||
Albo ręcznie — **wewnątrz `ConsentProvider`**:
|
||||
Or by hand — **inside `ConsentProvider`**:
|
||||
|
||||
```tsx
|
||||
import { PageStats } from '@intecion/ipal-kit/client'
|
||||
|
||||
<PageStats locale={locale} /> // endpoint domyślnie '/api/ipal/hit'
|
||||
<PageStats locale={locale} /> // endpoint defaults to '/api/ipal/hit'
|
||||
```
|
||||
|
||||
`<PageStats>` wysyła jeden beacon na odsłonę (także przy nawigacji klienckiej Next; `sendBeacon`,
|
||||
fallback `fetch` z `keepalive`). Nic nie renderuje. Propsy (`PageStatsProps`): `endpoint`
|
||||
(domyślnie `'/api/ipal/hit'`), `locale`.
|
||||
`<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: ścieżka, r?: referrer, l?: locale, v?: visitorId }`. Zawsze odpowiada `204` (także przy
|
||||
błędzie, odrzuceniu i przekroczeniu limitu 60 żądań/min na IP — scope `stats`). `v` jest zapisywane
|
||||
tylko, gdy cookie zgody z żądania ma `analytics: true` w aktualnej *Policy version* (wersja czytana
|
||||
z Cookie Settings, cache 1 min). Ścieżka: musi zaczynać się od `/`, max 300 znaków; wizyta: max 200
|
||||
odsłon. `locale` zapisywane, gdy pasuje do `xx` / `xx-XX`.
|
||||
`VISITOR_COOKIE` (`'ipal_vid'`) z `/client` — nazwa cookie, np. do własnej tabeli cookies.
|
||||
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: endpoint jest na tej samej domenie — `connect-src 'self'` wystarcza.
|
||||
CSP: the endpoint is on the same domain — `connect-src 'self'` is enough.
|
||||
|
||||
## Czego nie liczymy
|
||||
## What we do not count
|
||||
|
||||
- zalogowanych użytkowników panelu (redaktor oglądający stronę nie zawyża statystyk),
|
||||
- botów (Googlebot, podglądy linków, Lighthouse, curl, headless),
|
||||
- prefetchu Next (`sec-purpose: prefetch`),
|
||||
- odświeżenia tej samej strony w ciągu 10 s.
|
||||
- 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.
|
||||
|
||||
Zapisujemy samą ścieżkę: query string i `#hash` są odcinane (mogą zawierać e-mail, token, frazę
|
||||
wyszukiwania). Referrer — tylko nazwa domeny. Kraj — tylko z nagłówka Cloudflare `cf-ipcountry`, jeśli jest.
|
||||
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.
|
||||
|
||||
## Wizyta
|
||||
## Visit
|
||||
|
||||
Ciąg odsłon z przerwami poniżej 30 minut, w ramach jednego dnia. Restart serwera albo kilka instancji
|
||||
(każda ma własną sól) mogą rozbić trwającą wizytę na dwie — dla statystyk bez znaczenia. **Nie**
|
||||
zapisuj soli w bazie, żeby to „naprawić”: wtedy wczorajsze hashe dałoby się odwrócić do IP.
|
||||
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.
|
||||
|
||||
Wizyty starsze niż `retentionDays` są usuwane automatycznie (najwyżej raz na dobę na proces serwera,
|
||||
przy odsłonie). Sól zmienia się, gdy zmienia się `day` w strefie `timeZone`.
|
||||
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.
|
||||
|
||||
## Prawa odwiedzającego (RODO)
|
||||
## Visitor rights (GDPR)
|
||||
|
||||
- **Wycofanie zgody** — `useConsent` usuwa `ipal_vid` (jest w `DEFAULT_COOKIE_MAP.analytics`); kolejne
|
||||
odsłony są już anonimowe.
|
||||
- **Usunięcie danych** — odwiedzający podaje id z cookie `ipal_vid` (DevTools → Application →
|
||||
Cookies). W panelu: *Statistics → Visits*, filtr `visitorId` = id → zaznacz wszystko → Delete.
|
||||
Widok `/admin/stats?visitor=<id>` pokazuje to samo jako historię.
|
||||
- Wizyt anonimowych nie da się przypisać osobie — nie ma czego wydać ani usunąć na żądanie.
|
||||
- **Withdrawing consent** — `useConsent` deletes `ipal_vid` (it is in `DEFAULT_COOKIE_MAP.analytics`);
|
||||
further page views are anonymous.
|
||||
- **Deleting data** — the visitor gives the id from the `ipal_vid` cookie (DevTools → Application →
|
||||
Cookies). In the panel: *Statistics → Visits*, filter `visitorId` = 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.
|
||||
|
||||
## Do polityki prywatności i tabeli cookies
|
||||
## For the privacy policy and the cookie table
|
||||
|
||||
Dopisz w **Cookie Settings → Cookies** (panel) wiersz:
|
||||
Add a row in **Cookie Settings → Cookies** (panel):
|
||||
|
||||
| Nazwa | Dostawca | Kategoria | Cel | Czas |
|
||||
| Name | Provider | Category | Purpose | Duration |
|
||||
|---|---|---|---|---|
|
||||
| `ipal_vid` | ta strona | analytics | Rozpoznanie powracającego odwiedzającego w statystykach strony | 180 dni |
|
||||
| `ipal_vid` | this site | analytics | Recognising a returning visitor in the site statistics | 180 days |
|
||||
|
||||
Tekst do polityki prywatności (dopasuj nazwę administratora i okres):
|
||||
Privacy policy text — adjust the controller name and the retention period, paste the version for each
|
||||
language of the 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.
|
||||
```text
|
||||
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.
|
||||
```
|
||||
|
||||
## Wyłączenie, nadpisanie, rozszerzenie
|
||||
Polish version (for a `pl` site):
|
||||
|
||||
- **Wyłączenie:** bez opcji `stats` nic nie jest dodawane; `stats: { dashboard: false }` chowa tylko
|
||||
wykres z dashboardu; bez `<PageStats>` (lub `SiteProviders stats` = `false`) nic nie jest wysyłane.
|
||||
- **Nadpisanie:** `retentionDays`, `timeZone`; `<PageStats endpoint>` dla własnej ścieżki endpointu.
|
||||
Reguł liczenia (boty, prefetch, 30 min, 10 s) obecnie nie da się zmienić opcją.
|
||||
- **Rozszerzenie:** `STATS_SLUG` + typy `StatsOptions` / `StatsVisit` / `StatsPage` (z `@intecion/ipal-kit`)
|
||||
do własnych zapytań i raportów (Local API); `StatsView` / `StatsWidget` z `/admin` można wpiąć
|
||||
ręcznie. Budowniczowie kolekcji i endpointu nie są obecnie publicznie eksportowane.
|
||||
```text
|
||||
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 `stats` option nothing is added; `stats: { dashboard: false }` hides only
|
||||
the dashboard chart; without `<PageStats>` (or with `SiteProviders stats` = `false`) nothing is sent.
|
||||
- **Override:** `retentionDays`, `timeZone`; `<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 types `StatsOptions` / `StatsVisit` / `StatsPage` (from
|
||||
`@intecion/ipal-kit`) for your own queries and reports (Local API); `StatsView` / `StatsWidget` from
|
||||
`/admin` can be wired by hand. The collection and endpoint builders are currently not publicly
|
||||
exported.
|
||||
|
||||
Reference in New Issue
Block a user