Cookie scanner, phase 1: declarations, database lookup, review list
ipalKit({ cookieScanner }) (opt-in) adds the cookie-review collection, a
"Scan cookies" box above its list and GET/POST /api/ipal/cookie-scan. A scan
lists the cookies of every integration the project switches on (consent,
admin login, locale, stats, GA4, GTM, Meta Pixel, Clarity, LinkedIn, TikTok,
Turnstile), the project's own declarations, and extra names looked up in the
bundled Open Cookie Database, as drafts. Editors accept (→ Cookie Settings →
Cookies, every locale, only empty text filled), edit or reject. A rescan never
deletes, never changes status and never overwrites edited text.
Everything is overridable (access, collectionOverrides, integrations,
declarations, databaseCategories, labels, syncAccepted) and the building
blocks are exported. Admin labels in en + pl. Docs: cookie-scanner.md,
consent.md, AGENT.md, ipal-reference, ipal-consent-check.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
ab45cf48be
commit
a0545b6716
@@ -0,0 +1,292 @@
|
||||
import type { CookieDeclaration, CookieIntegration, CookieScanContext } from './types.js'
|
||||
|
||||
import { validAnalyticsId } from '../../analytics/idFormats.js'
|
||||
import { LOCALE_COOKIE_NAME } from '../../i18n/negotiateLocale.js'
|
||||
import { getTurnstileConfig } from '../../turnstile/config.js'
|
||||
import { CONSENT_COOKIE } from '../storage.js'
|
||||
|
||||
/** A tag ID from Site Integrations is filled in and valid. */
|
||||
const hasId = (field: string) => (ctx: CookieScanContext) =>
|
||||
Boolean(validAnalyticsId(field as never, ctx.integrations[field]))
|
||||
|
||||
const T = (en: string, pl: string) => ({ en, pl })
|
||||
const SESSION = T('Session', 'Sesja')
|
||||
const days = (n: number) => T(`${n} days`, `${n} dni`)
|
||||
const months = (n: number) => T(`${n} months`, `${n} mies.`)
|
||||
const YEAR = T('1 year', '1 rok')
|
||||
const TWO_YEARS = T('2 years', '2 lata')
|
||||
const SITE = 'This site'
|
||||
|
||||
/**
|
||||
* Cookies of everything the plugin itself injects — one place per integration.
|
||||
* Each one is part of a scan only when this project switches it on (an ID in
|
||||
* Site Integrations, a plugin option). Change the list with
|
||||
* `cookieScanner.integrations: (defaults) => …`.
|
||||
*/
|
||||
export const DEFAULT_COOKIE_INTEGRATIONS: CookieIntegration[] = [
|
||||
{
|
||||
declarations: [
|
||||
{
|
||||
name: CONSENT_COOKIE,
|
||||
category: 'necessary',
|
||||
purpose: T('Stores your cookie consent decision.', 'Zapamiętuje Twoją decyzję w sprawie plików cookie.'),
|
||||
retention: months(6),
|
||||
setBeforeConsent: false,
|
||||
vendor: SITE,
|
||||
},
|
||||
],
|
||||
isEnabled: () => true,
|
||||
key: 'consent',
|
||||
label: 'Cookie banner',
|
||||
},
|
||||
{
|
||||
declarations: (ctx) => [
|
||||
{
|
||||
name: `${ctx.payload.config.cookiePrefix ?? 'payload'}-token`,
|
||||
category: 'necessary',
|
||||
purpose: T('Session of a logged-in editor (admin panel only).', 'Sesja zalogowanego redaktora (tylko panel administracyjny).'),
|
||||
retention: T('Until logout (2 hours by default)', 'Do wylogowania (domyślnie 2 godziny)'),
|
||||
setBeforeConsent: true,
|
||||
vendor: SITE,
|
||||
},
|
||||
],
|
||||
isEnabled: () => true,
|
||||
key: 'admin',
|
||||
label: 'Admin panel login',
|
||||
},
|
||||
{
|
||||
declarations: [
|
||||
{
|
||||
name: LOCALE_COOKIE_NAME,
|
||||
category: 'functional',
|
||||
purpose: T('Remembers the selected site language.', 'Zapamiętuje wybrany język strony.'),
|
||||
retention: SESSION,
|
||||
setBeforeConsent: false,
|
||||
vendor: SITE,
|
||||
},
|
||||
],
|
||||
isEnabled: (ctx) => ctx.plugin.localeCount > 1,
|
||||
key: 'locale',
|
||||
label: 'Language choice',
|
||||
},
|
||||
{
|
||||
declarations: [
|
||||
{
|
||||
name: 'ipal_vid', // VISITOR_COOKIE — that file is a client component
|
||||
category: 'analytics',
|
||||
purpose: T(
|
||||
'Built-in statistics: random visitor id that joins your visits across days. Set only with analytics consent.',
|
||||
'Wbudowane statystyki: losowy identyfikator łączący Twoje wizyty z różnych dni. Tylko po zgodzie na analitykę.',
|
||||
),
|
||||
retention: months(6),
|
||||
setBeforeConsent: false,
|
||||
vendor: SITE,
|
||||
},
|
||||
],
|
||||
isEnabled: (ctx) => ctx.plugin.stats,
|
||||
key: 'stats',
|
||||
label: 'Built-in statistics',
|
||||
},
|
||||
{
|
||||
declarations: [
|
||||
{
|
||||
name: '_ga',
|
||||
category: 'analytics',
|
||||
purpose: T('Google Analytics: distinguishes users in statistics.', 'Google Analytics: rozróżnia użytkowników w statystykach.'),
|
||||
retention: TWO_YEARS,
|
||||
setBeforeConsent: false,
|
||||
vendor: 'Google',
|
||||
},
|
||||
{
|
||||
name: '_ga_*',
|
||||
category: 'analytics',
|
||||
purpose: T('Google Analytics: keeps the session state.', 'Google Analytics: przechowuje stan sesji.'),
|
||||
retention: TWO_YEARS,
|
||||
setBeforeConsent: false,
|
||||
vendor: 'Google',
|
||||
},
|
||||
],
|
||||
isEnabled: hasId('ga4MeasurementId'),
|
||||
key: 'ga4',
|
||||
label: 'Google Analytics 4',
|
||||
},
|
||||
{
|
||||
// GTM itself sets no cookie; its tags do. The Conversion Linker (Google Ads)
|
||||
// is the usual one — anything else the container fires shows up in a crawl.
|
||||
declarations: [
|
||||
{
|
||||
name: '_gcl_*',
|
||||
category: 'marketing',
|
||||
purpose: T(
|
||||
'Google Ads (via Google Tag Manager): attributes conversions to ad clicks.',
|
||||
'Google Ads (przez Google Tag Manager): przypisuje konwersje do kliknięć reklam.',
|
||||
),
|
||||
retention: months(3),
|
||||
setBeforeConsent: false,
|
||||
vendor: 'Google',
|
||||
},
|
||||
],
|
||||
isEnabled: hasId('gtmContainerId'),
|
||||
key: 'gtm',
|
||||
label: 'Google Tag Manager',
|
||||
},
|
||||
{
|
||||
declarations: [
|
||||
{
|
||||
name: '_fbp',
|
||||
category: 'marketing',
|
||||
purpose: T('Meta Pixel: ad measurement and targeting.', 'Meta Pixel: pomiar i dopasowanie reklam.'),
|
||||
retention: months(3),
|
||||
setBeforeConsent: false,
|
||||
vendor: 'Meta',
|
||||
},
|
||||
{
|
||||
name: '_fbc',
|
||||
category: 'marketing',
|
||||
purpose: T('Meta Pixel: stores the last ad click.', 'Meta Pixel: zapamiętuje ostatnie kliknięcie reklamy.'),
|
||||
retention: months(3),
|
||||
setBeforeConsent: false,
|
||||
vendor: 'Meta',
|
||||
},
|
||||
],
|
||||
isEnabled: hasId('metaPixelId'),
|
||||
key: 'metaPixel',
|
||||
label: 'Meta Pixel',
|
||||
},
|
||||
{
|
||||
declarations: [
|
||||
{
|
||||
name: '_clck',
|
||||
category: 'analytics',
|
||||
purpose: T('Clarity: user id for behaviour analytics.', 'Clarity: identyfikator użytkownika w analizie zachowań.'),
|
||||
retention: YEAR,
|
||||
setBeforeConsent: false,
|
||||
vendor: 'Microsoft Clarity',
|
||||
},
|
||||
{
|
||||
name: '_clsk',
|
||||
category: 'analytics',
|
||||
purpose: T('Clarity: joins page views into one session.', 'Clarity: łączy odsłony w jedną sesję.'),
|
||||
retention: T('1 day', '1 dzień'),
|
||||
setBeforeConsent: false,
|
||||
vendor: 'Microsoft Clarity',
|
||||
},
|
||||
{
|
||||
name: 'CLID',
|
||||
category: 'analytics',
|
||||
domain: 'clarity.ms',
|
||||
purpose: T('Clarity: user id across sites using Clarity.', 'Clarity: identyfikator użytkownika między stronami z Clarity.'),
|
||||
retention: YEAR,
|
||||
setBeforeConsent: false,
|
||||
vendor: 'Microsoft Clarity',
|
||||
},
|
||||
{
|
||||
name: 'MUID',
|
||||
category: 'marketing',
|
||||
domain: 'clarity.ms',
|
||||
purpose: T('Microsoft: browser id used across Microsoft services and ads.', 'Microsoft: identyfikator przeglądarki w usługach i reklamach Microsoft.'),
|
||||
retention: YEAR,
|
||||
setBeforeConsent: false,
|
||||
vendor: 'Microsoft',
|
||||
},
|
||||
],
|
||||
isEnabled: hasId('clarityProjectId'),
|
||||
key: 'clarity',
|
||||
label: 'Microsoft Clarity',
|
||||
},
|
||||
{
|
||||
declarations: [
|
||||
{
|
||||
name: 'li_fat_id',
|
||||
category: 'marketing',
|
||||
purpose: T('LinkedIn Insight Tag: conversion attribution.', 'LinkedIn Insight Tag: przypisanie konwersji.'),
|
||||
retention: days(30),
|
||||
setBeforeConsent: false,
|
||||
vendor: 'LinkedIn',
|
||||
},
|
||||
{
|
||||
name: 'bcookie',
|
||||
category: 'marketing',
|
||||
domain: 'linkedin.com',
|
||||
purpose: T('LinkedIn: browser id.', 'LinkedIn: identyfikator przeglądarki.'),
|
||||
retention: YEAR,
|
||||
setBeforeConsent: false,
|
||||
vendor: 'LinkedIn',
|
||||
},
|
||||
{
|
||||
name: 'lidc',
|
||||
category: 'marketing',
|
||||
domain: 'linkedin.com',
|
||||
purpose: T('LinkedIn: data-centre routing.', 'LinkedIn: wybór centrum danych.'),
|
||||
retention: T('1 day', '1 dzień'),
|
||||
setBeforeConsent: false,
|
||||
vendor: 'LinkedIn',
|
||||
},
|
||||
{
|
||||
name: 'UserMatchHistory',
|
||||
category: 'marketing',
|
||||
domain: 'linkedin.com',
|
||||
purpose: T('LinkedIn Ads: id sync with ad partners.', 'LinkedIn Ads: synchronizacja identyfikatorów z partnerami reklamowymi.'),
|
||||
retention: days(30),
|
||||
setBeforeConsent: false,
|
||||
vendor: 'LinkedIn',
|
||||
},
|
||||
],
|
||||
isEnabled: hasId('linkedInPartnerId'),
|
||||
key: 'linkedIn',
|
||||
label: 'LinkedIn Insight Tag',
|
||||
},
|
||||
{
|
||||
declarations: [
|
||||
{
|
||||
name: '_ttp',
|
||||
category: 'marketing',
|
||||
purpose: T('TikTok Pixel: ad measurement.', 'TikTok Pixel: pomiar reklam.'),
|
||||
retention: months(13),
|
||||
setBeforeConsent: false,
|
||||
vendor: 'TikTok',
|
||||
},
|
||||
{
|
||||
name: '_tt_enable_cookie',
|
||||
category: 'marketing',
|
||||
purpose: T('TikTok Pixel: checks that cookies work.', 'TikTok Pixel: sprawdza, czy cookies działają.'),
|
||||
retention: months(13),
|
||||
setBeforeConsent: false,
|
||||
vendor: 'TikTok',
|
||||
},
|
||||
],
|
||||
isEnabled: hasId('tiktokPixelId'),
|
||||
key: 'tiktok',
|
||||
label: 'TikTok Pixel',
|
||||
},
|
||||
{
|
||||
// Turnstile hands back a one-time token; cf_clearance appears only when the
|
||||
// widget has pre-clearance switched on in the Cloudflare dashboard.
|
||||
declarations: [
|
||||
{
|
||||
name: 'cf_clearance',
|
||||
category: 'necessary',
|
||||
purpose: T(
|
||||
'Cloudflare Turnstile: proves the anti-spam check was passed (only with pre-clearance on).',
|
||||
'Cloudflare Turnstile: potwierdza przejście zabezpieczenia antyspamowego (tylko z włączonym pre-clearance).',
|
||||
),
|
||||
retention: T('30 minutes (set in Cloudflare)', '30 minut (ustawiane w Cloudflare)'),
|
||||
setBeforeConsent: true,
|
||||
vendor: 'Cloudflare',
|
||||
},
|
||||
],
|
||||
isEnabled: async (ctx) => (await getTurnstileConfig(ctx.payload)).enabled,
|
||||
key: 'turnstile',
|
||||
label: 'Cloudflare Turnstile',
|
||||
},
|
||||
]
|
||||
|
||||
/** An integration's declarations for this project. */
|
||||
export function declarationsOf(integration: CookieIntegration, ctx: CookieScanContext): CookieDeclaration[] {
|
||||
return typeof integration.declarations === 'function' ? integration.declarations(ctx) : integration.declarations
|
||||
}
|
||||
|
||||
/** True when `name` matches `pattern` (a trailing `*` = prefix). */
|
||||
export function cookieNameMatches(pattern: string, name: string): boolean {
|
||||
return pattern.endsWith('*') ? name.startsWith(pattern.slice(0, -1)) : name === pattern
|
||||
}
|
||||
Reference in New Issue
Block a user