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:
Radosław Smoliński
2026-10-22 17:59:52 +02:00
co-authored by Claude Opus 5.5
107 changed files with 5476 additions and 2541 deletions
+137 -112
View File
@@ -1,58 +1,59 @@
# analytics
Ładuje tagi analityczne i marketingowe wpisane w panelu, każdy zgodnie ze
zgodą z modułu consent:
Loads the analytics and marketing tags entered in the admin panel, each one
according to the consent from the consent module:
- **Google (GA4 / GTM)** — przez Consent Mode v2 w trybie *advanced*: skrypt
`googletagmanager.com` ładuje się **od razu, także przed zgodą** (bez `defer`),
ale najpierw dostaje `consent default` z zapisaną decyzją albo wszystko
`denied`. Przy `denied` Google nie zapisuje ciasteczek (`_ga`), ale może wysyłać
bezciasteczkowe pingi — to **nie** jest „zero żądań przed zgodą”. Jeśli
wymagasz trybu *basic* (brak żądań do Google przed zgodą), plugin go dziś nie
oferuje.
- **Pozostałe (Meta Pixel, Microsoft Clarity, LinkedIn Insight, TikTok Pixel)** —
nie mają Consent Mode, więc ładują się **dopiero po zgodzie** na właściwą
kategorię. Reagują na żywo: klik „Akceptuj” → tag startuje bez przeładowania.
- **Google (GA4 / GTM)** — through Consent Mode v2. The tag always gets a
`consent default` first, with the visitor's stored decision (before a decision:
everything `denied`). Then it depends on `consentMode`:
- `'advanced'` (default): the `googletagmanager.com` script loads **right away,
also before consent**. With `denied`, Google stores no cookies (`_ga`), but it
can send cookieless pings — this is **not** "zero requests before consent".
- `'basic'`: **zero requests to Google before consent** — the script waits until
the visitor grants analytics or marketing (see "How Consent Mode works" below).
- **Others (Meta Pixel, Microsoft Clarity, LinkedIn Insight, TikTok Pixel)** —
they have no Consent Mode, so they load **only after consent** for their
category. They react live: click "Accept" → the tag starts without a reload.
## Config
Brak opcji w `payload.config` — plugin czyta ID z globala **Site Integrations**
(Settings → Site Integrations):
No options in `payload.config` — the plugin reads the IDs from the **Site
Integrations** global (Settings → Site Integrations):
| Pole (`name`) | Format (walidowany) | Kategoria zgody |
| Field (`name`) | Format (validated) | Consent category |
|---|---|---|
| GA4 Measurement ID (`ga4MeasurementId`) | `G-` + 4–20 `[A-Z0-9]` | Consent Mode (analytics_storage) |
| GTM Container ID (`gtmContainerId`) | `GTM-` + 4–12 `[A-Z0-9]` | Consent Mode (wszystkie sygnały) |
| Meta Pixel ID (`metaPixelId`) | 5–20 cyfr | **marketing** |
| Microsoft Clarity Project ID (`clarityProjectId`) | 5–20 znaków `[a-z0-9]` | **analytics** |
| LinkedIn Partner ID (`linkedInPartnerId`) | 3–12 cyfr | **marketing** |
| TikTok Pixel ID (`tiktokPixelId`) | 10–30 znaków `[A-Z0-9]` | **marketing** |
| GTM Container ID (`gtmContainerId`) | `GTM-` + 4–12 `[A-Z0-9]` | Consent Mode (all signals) |
| Meta Pixel ID (`metaPixelId`) | 5–20 digits | **marketing** |
| Microsoft Clarity Project ID (`clarityProjectId`) | 5–20 characters `[a-z0-9]` | **analytics** |
| LinkedIn Partner ID (`linkedInPartnerId`) | 3–12 digits | **marketing** |
| TikTok Pixel ID (`tiktokPixelId`) | 10–30 characters `[A-Z0-9]` | **marketing** |
GA4 + GTM ustawione jednocześnie → wygrywa GTM (GA4 nie jest wtedy ładowane
osobno). Puste pole = tag się nie ładuje. Format jest sprawdzany przy zapisie w
panelu, a `getAnalyticsConfig` dodatkowo przycina spacje i zwraca `null` dla
ID w złym formacie (np. z importu) — taki tag się nie ładuje.
GA4 + GTM set at the same time → GTM wins (GA4 is then not loaded separately).
Empty field = the tag does not load. The format is checked on save in the panel,
and `getAnalyticsConfig` also trims spaces and returns `null` for an ID in a
wrong format (e.g. from an import) — such a tag does not load.
Wszystkie te ID są publiczne (widać je w źródle strony). `getAnalyticsConfig`
czyta wyłącznie je, więc sekrety (Turnstile, SMTP) nie mają jak wyciec.
All these IDs are public (they are visible in the page source).
`getAnalyticsConfig` reads only them, so secrets (Turnstile, SMTP) cannot leak.
### Pixel w panelu czy w GTM?
### Pixel in the panel or in GTM?
**Jedno albo drugie, nigdy oba** — inaczej każde zdarzenie liczy się
podwójnie. Zasada:
**One or the other, never both** — otherwise every event is counted twice. The
rule:
- Klient bez GTM / prosta strona → wpisz Pixel ID w panelu (najprościej,
zgoda obsłużona automatycznie).
- Klient ma agencję/marketera, który zarządza tagami w GTM → zostaw pole Pixel
puste, Pixel konfiguruje się w GTM z warunkiem `ad_storage` (patrz sekcja
„Meta Pixel przez GTM” niżej).
- Client without GTM / simple site → enter the Pixel ID in the panel (simplest,
consent handled automatically).
- Client has an agency/marketer who manages tags in GTM → leave the Pixel field
empty; the Pixel is configured in GTM with an `ad_storage` condition (see the
section "Meta Pixel via GTM" below).
### Zdarzenia konwersji (non-Google)
### Conversion events (non-Google)
`Analytics` wysyła tylko `PageView` (Meta) / `ttq.page()` (TikTok) — **raz, przy
załadowaniu tagu**; nawigacja client-side Next.js nie generuje kolejnych
PageView. Konwersje (np. Lead po formularzu) wołasz
sam — globale istnieją dopiero po zgodzie, więc zawsze ze strażnikiem:
`Analytics` sends only `PageView` (Meta) / `ttq.page()` (TikTok) — **once, when
the tag loads**; Next.js client-side navigation does not generate more
PageViews. You call conversions (e.g. Lead after a form) yourself — the globals
exist only after consent, so always with a guard:
```ts
window.fbq?.('track', 'Lead') // Meta
@@ -60,13 +61,13 @@ window.ttq?.track('SubmitForm') // TikTok
window.lintrk?.('track', { conversion_id: 123 }) // LinkedIn
```
Niskopoziomowe loadery (`loadMetaPixel`, `loadClarity`, `loadLinkedIn`,
`loadTikTok`) są eksportowane z `/client`, ale normalnie nie są potrzebne —
NIE wołaj ich z pominięciem zgody.
The low-level loaders (`loadMetaPixel`, `loadClarity`, `loadLinkedIn`,
`loadTikTok`) are exported from `/client`, but normally you do not need them —
NEVER call them in a way that skips consent.
## Front
W layoucie locale, **wewnątrz `ConsentProvider`**:
In the locale layout, **inside `ConsentProvider`**:
```tsx
import { getAnalyticsConfig } from '@intecion/ipal-kit'
@@ -86,88 +87,108 @@ export default async function LocaleLayout({ children, params }) {
}
```
`Analytics` nie renderuje nic — wstrzykuje skrypty. Zamontuj raz, wysoko w
drzewie.
With `SiteProviders` (`/rsc`) you do not mount it yourself — options go through
`<SiteProviders analytics={{ consentMode, defer, deferTimeoutMs }}>` (`false` = no tags).
| Prop | Typ | Domyślnie | Opis |
`Analytics` renders nothing — it injects scripts. Mount it once, high in the
tree.
| Prop | Type | Default | Description |
|---|---|---|---|
| `ga4MeasurementId`, `gtmContainerId`, `metaPixelId`, `clarityProjectId`, `linkedInPartnerId`, `tiktokPixelId` | `string \| null` | — | z `getAnalyticsConfig` (`AnalyticsConfig`) |
| `defer` | `boolean` | `false` | tryb Core Web Vitals (niżej) |
| `deferTimeoutMs` | `number` | `3500` | fallback po `load`, ms | **Musi być wewnątrz `ConsentProvider`** (od 1.7.12 czyta stan zgody na
żywo — poza providerem rzuci błąd kontekstu).
| `ga4MeasurementId`, `gtmContainerId`, `metaPixelId`, `clarityProjectId`, `linkedInPartnerId`, `tiktokPixelId` | `string \| null` | — | from `getAnalyticsConfig` (`AnalyticsConfig`) |
| `consentMode` | `'advanced' \| 'basic'` | `'advanced'` | when the Google tag may load (below) |
| `defer` | `boolean` | `false` | Core Web Vitals mode (below) |
| `deferTimeoutMs` | `number` | `3500` | fallback after `load`, ms |
## Tryb Core Web Vitals — `defer` (opcjonalny)
**It must be inside `ConsentProvider`** (since 1.7.12 it reads the consent state
live — outside the provider it throws a context error).
## Core Web Vitals mode — `defer` (optional)
```tsx
<Analytics {...analytics} defer /> // domyślnie 3500 ms
<Analytics {...analytics} defer /> // default 3500 ms
<Analytics {...analytics} defer deferTimeoutMs={5000} />
```
Wszystkie tagi (GA4/GTM i pixele) ładują się z sieci dopiero przy **pierwszej
interakcji** (scroll, klik, dotyk, klawisz) albo `deferTimeoutMs` po `load`,
w zależności od tego, co nastąpi pierwsze. ~100+ KiB JS wypada z okna FCP/LCP.
All tags (GA4/GTM and pixels) load from the network only on the **first
interaction** (scroll, click, touch, key) or `deferTimeoutMs` after `load`,
whichever comes first. ~100+ KiB of JS drops out of the FCP/LCP window.
Defer zmienia **kiedy**, nigdy **czy**:
- domyślny stan Consent Mode nadal idzie od razu (to tylko push do dataLayer, bez
ruchu sieciowego), więc GA nigdy nie startuje bez niego;
- pixele non-Google nadal wymagają zgody na swoją kategorię.
Defer changes **when**, never **whether**:
- the default Consent Mode state is still sent right away (it is only a push to
dataLayer, no network traffic), so GA never starts without it;
- non-Google pixels still need consent for their category;
- with `consentMode: 'basic'` the Google tag waits for both: consent and the
defer moment.
Koszt: odwiedzający, którzy wyjdą przed interakcją i przed upływem timeoutu, nie
zostaną policzeni (trochę mniej sesji w GA). Domyślnie `defer` jest wyłączony.
Cost: visitors who leave before interacting and before the timeout are not
counted (slightly fewer sessions in GA). `defer` is off by default.
Brakujące opcje najlepiej zgłaszać do ipal-kit (core = engine) — kopia
komponentu w projekcie nie dostaje poprawek z aktualizacji.
Report missing options to ipal-kit (core = engine) — a copy of the component in
the project does not get fixes from updates.
## Jak działa Consent Mode
## How Consent Mode works
1. Przed załadowaniem tagu: `gtag('consent', 'default', { …, wait_for_update: 500 })`
z zapisaną decyzją odwiedzającego (albo wszystko `denied`, gdy jeszcze nie
zdecydował lub zgoda jest z innej wersji polityki — `texts.version`).
2. Tag się ładuje i respektuje ten stan od pierwszego trafienia.
3. Klik w banerze → `gtag('consent', 'update', …)` → tagi reagują natychmiast.
**`basic` vs `advanced` mode.** `<SiteProviders analytics={{ consentMode: 'basic' }}>` (or
`<Analytics consentMode="basic" />`): the `googletagmanager.com` script does not load until the
visitor consents to analytics or marketing — the "zero tags before consent" requirement. The cost is
no conversion modelling for visitors without consent. The default `advanced` loads the tag right away
with `denied` signals. In both modes the Consent Mode default is set first. The mode is the client's
decision — record it in `AGENTS.md` → "Project decisions".
Wycofanie zgody (true → false) kasuje ciasteczka kategorii (`_ga*`, `_fbp`,
`_clck`, `_ttp`, … — patrz [consent.md](./consent.md)) i wysyła `update` do
Google, ale **już załadowane skrypty non-Google (Meta, Clarity, LinkedIn,
TikTok) zostają na stronie do przeładowania** — plugin ich nie wyładowuje.
1. Before the tag loads: `gtag('consent', 'default', { …, wait_for_update: 500 })`
with the visitor's stored decision (or everything `denied` when they have not
decided yet or the consent is from another policy version — `texts.version`).
2. The tag loads (`advanced`: right away; `basic`: after consent for analytics or
marketing) and respects that state from the first hit.
3. Click in the banner → `gtag('consent', 'update', …)` → tags react immediately.
Mapowanie kategorii na sygnały Google:
Withdrawing consent (true → false) deletes the category's cookies (`_ga*`, `_fbp`,
`_clck`, `_ttp`, … — see [consent.md](./consent.md)) and sends an `update` to
Google, but **non-Google scripts that are already loaded (Meta, Clarity,
LinkedIn, TikTok) stay on the page until reload** — the plugin does not unload
them. The same goes for a Google tag already loaded in `basic` mode — from then
on it is governed by the Consent Mode `update`.
| Kategoria | Sygnały |
Mapping of categories to Google signals:
| Category | Signals |
|---|---|
| analytics | `analytics_storage` |
| marketing | `ad_storage`, `ad_user_data`, `ad_personalization` |
| functional | `functionality_storage`, `personalization_storage` |
| necessary | `security_storage` (zawsze `granted`) |
| necessary | `security_storage` (always `granted`) |
## Testowanie
## Testing
W konsoli: `window.dataLayer` — powinien zawierać `Arguments(3)` z `consent` /
`default`, a po decyzji `consent` / `update`. Jeśli widzisz `Array` zamiast
`Arguments`, komenda nie zostanie rozpoznana przez Google.
In the console: `window.dataLayer` — it should contain `Arguments(3)` with
`consent` / `default`, and after the decision `consent` / `update`. If you see
`Array` instead of `Arguments`, Google will not recognise the command.
Ciasteczko `_ga` pojawia się dopiero po zgodzie na analytics — to jest sedno
The `_ga` cookie appears only after consent for analytics — that is the core of
Consent Mode.
Google: przed zgodą w Network **będzie** żądanie do `googletagmanager.com` (i
ew. bezciasteczkowe pingi `collect` z `gcs=G100`) — to oczekiwane w trybie advanced.
Google, `advanced` mode: before consent the Network tab **will** show a request
to `googletagmanager.com` (and possibly cookieless `collect` pings with
`gcs=G100`) — this is expected. `basic` mode: before consent there **must not**
be any request to `googletagmanager.com` / `google-analytics.com`.
Pixele non-Google: przed zgodą w Network **nie może** być żądań do
Non-Google pixels: before consent the Network tab **must not** show requests to
`connect.facebook.net`, `clarity.ms`, `snap.licdn.com`, `analytics.tiktok.com`.
Po kliknięciu zgody pojawiają się od razu. Meta Pixel Helper (rozszerzenie
Chrome) powinien pokazać `PageView` dopiero po akceptacji marketingu.
After clicking consent they appear right away. Meta Pixel Helper (Chrome
extension) should show `PageView` only after marketing is accepted.
## Zdarzenia do GTM — pushDataLayer
## Events for GTM — pushDataLayer
Do wypchnięcia własnego zdarzenia (np. `form_submit` pod tag Lead w GTM) jest
helper `pushDataLayer` (SSR-safe, buforuje gdy GTM jeszcze nie wstał):
To push your own event (e.g. `form_submit` for a Lead tag in GTM) use the
`pushDataLayer` helper (SSR-safe, buffers when GTM is not up yet):
```tsx
import { pushDataLayer } from '@intecion/ipal-kit/client'
pushDataLayer('form_submit', { form_name: 'kontakt' })
```
Najczęstsze użycie — `onSuccess` formularza (patrz [forms.md](./forms.md)):
The most common use — the form's `onSuccess` (see [forms.md](./forms.md)):
```tsx
const f = useContactForm({
@@ -176,32 +197,36 @@ const f = useContactForm({
})
```
**To tylko emisja zdarzenia — zgodę nadal gatuje GTM** (`ad_storage` dla tagów
marketingowych jak Meta Pixel). `pushDataLayer` nie omija consentu; daje GTM
czysty event, na którym tag może się odpalić, gdy zgoda jest udzielona.
**This only emits the event — GTM still gates consent** (`ad_storage` for
marketing tags such as Meta Pixel). `pushDataLayer` does not bypass consent; it
gives GTM a clean event on which a tag can fire when consent is granted.
**GTM sam nie ustawia ciasteczek** — to pojemnik. Bez opublikowanego (Submit →
Publish, nie sam zapis) tagu GA4 w kontenerze wszystko wygląda dobrze:
`gtm.load` w dataLayer, Tag Assistant widzi kontener — a `_ga` nie ma, bo nic go
nie tworzy. Przy debugowaniu warto tymczasowo wyczyścić GTM Container ID i
zostawić samo GA4, żeby wyeliminować kontener jako zmienną.
**GTM sets no cookies by itself** — it is a container. Without a published
(Submit → Publish, not just save) GA4 tag in the container everything looks
fine: `gtm.load` in dataLayer, Tag Assistant sees the container — but there is no
`_ga`, because nothing creates it. When debugging, temporarily clear the GTM
Container ID and keep GA4 alone, to rule out the container as a variable.
---
## Wyłączenie, nadpisanie, rozszerzenie
## Turn off, override, extend
- **Wyłączenie:** nie montuj `<Analytics>` (albo `SiteProviders analytics={false}`) albo zostaw puste
pola ID w Site Integrations. Zakładka *Analytics* w globalu `site-integrations` jest obecnie zawsze dodawana.
- **Nadpisanie:** propsy `<Analytics>` to zwykłe ID — możesz podać własne zamiast `getAnalyticsConfig`;
`defer` / `deferTimeoutMs` zmieniają moment ładowania. Trybu Consent Mode *basic* i mapowania
kategorii na sygnały Google obecnie nie da się zmienić opcją.
- **Rozszerzenie:** inne skrypty → `ConsentScript` ([consent.md](./consent.md)); niskopoziomowe
`loadMetaPixel` / `loadClarity` / `loadLinkedIn` / `loadTikTok`, `pushDataLayer` z `/client`;
`setDefaultConsent` / `updateConsent` z roota; własne pola w Site Integrations przez
`ipalKit({ integrationsFields })` (zakładka *Custom*).
- **Turn off:** do not mount `<Analytics>` (or `SiteProviders analytics={false}`), or leave the ID
fields in Site Integrations empty. The *Analytics* tab in the `site-integrations` global is currently
always added (you can hide or change it with `ipalKit({ globalOverrides: { 'site-integrations': … } })`).
- **Override:** the `<Analytics>` props are plain IDs — you can pass your own instead of
`getAnalyticsConfig`; `consentMode` (`'advanced'` / `'basic'`) sets when the Google tag may load;
`defer` / `deferTimeoutMs` change when tags load. Access and hooks of the `site-integrations` global:
`ipalKit({ globalOverrides: { 'site-integrations': { access: { … }, hooks: { … } } } })` (your access
rules win, your hooks run after the plugin's; a function gets the whole global). The mapping of
categories to Google signals currently cannot be changed with an option.
- **Extend:** other scripts → `ConsentScript` ([consent.md](./consent.md)); low-level
`loadMetaPixel` / `loadClarity` / `loadLinkedIn` / `loadTikTok`, `pushDataLayer` from `/client`;
`setDefaultConsent` / `updateConsent` from the root; your own fields in Site Integrations via
`ipalKit({ integrationsFields })` (*Custom* tab).
## Meta Pixel przez GTM
## Meta Pixel via GTM
Wariant dla klientów, u których tagami zarządza marketer w GTM (pole **Meta
Pixel ID** w panelu zostaje wtedy **puste** — inaczej podwójne zliczanie).
Pełny przewodnik krok po kroku: [gtm-meta-pixel.md](./gtm-meta-pixel.md).
A variant for clients whose tags are managed by a marketer in GTM (the **Meta
Pixel ID** field in the panel then stays **empty** — otherwise double counting).
Full step-by-step guide: [gtm-meta-pixel.md](./gtm-meta-pixel.md).