- Theme choice in localStorage under 'theme' (next-themes' key and values)
instead of 'ipal-theme'. ThemeScript moves an old choice before the first
paint and removes the old key; useTheme / ThemeSwitcher do the same
without the script. ipalKit({ theme: { storageKey } }) sets an own key,
which reaches ThemeScript through getSiteShell().theme and <html
data-theme-storage>.
- The cookie scanner declares the theme key (Theme choice: local storage,
necessary, until changed or site data is cleared) when the theme switch
is on, so Scan cookies finds it without a crawl.
- Cookies -> Cookie list rows get a Type (cookie / local storage / session
storage, default cookie, shared by every language), filled by scan, review
and approval. The detailed settings window and <CookieTable> show it with
English and Polish defaults; the approval page marks storage entries.
- Migration: adds cookie_settings_cookies.storage (DEFAULT 'cookie') and
cookie_settings_locales.detail_labels_storage, nothing else.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
336 lines
12 KiB
TypeScript
336 lines
12 KiB
TypeScript
import type { AdminTextKey } from '../../admin-i18n/texts/index.js'
|
|
import type { CookieDeclaration, CookieIntegration, CookieScanContext } from './types.js'
|
|
|
|
import { adminTexts } from '../../admin-i18n/texts/index.js'
|
|
import { validAnalyticsId } from '../../analytics/idFormats.js'
|
|
import { LOCALE_COOKIE_NAME } from '../../i18n/negotiateLocale.js'
|
|
import { THEME_STORAGE_KEY } from '../../theme/theme.js'
|
|
import { getTurnstileConfig } from '../../turnstile/config.js'
|
|
import { CONSENT_COOKIE } from '../storage.js'
|
|
import { textFor } from './merge.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'
|
|
const UNTIL_CHANGED = T('Until changed or site data is cleared', 'Do zmiany lub wyczyszczenia danych witryny')
|
|
|
|
/** Site Settings → Theme → visitors may switch: only then is the choice stored. */
|
|
async function themeToggleOn(ctx: CookieScanContext): Promise<boolean> {
|
|
try {
|
|
const settings = (await ctx.payload.findGlobal({ slug: 'site-settings' as never, depth: 0 })) as { allowThemeToggle?: boolean }
|
|
return settings.allowThemeToggle === true
|
|
} catch {
|
|
return false
|
|
}
|
|
}
|
|
/** A name from the shared admin texts, in every admin language the plugin ships. */
|
|
const A = (key: AdminTextKey) => ({ en: adminTexts.en[key], pl: adminTexts.pl[key] })
|
|
|
|
/** Source name of the project's own `cookieScanner.declarations`. */
|
|
export const PROJECT_SOURCE = A('cookieSourceProject')
|
|
|
|
/**
|
|
* 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: A('cookieIntegrationConsent'),
|
|
},
|
|
{
|
|
// Browser storage, not a cookie: the light / dark choice the visitor made themselves —
|
|
// a preference they asked for, so necessary (no separate consent); editable in review.
|
|
declarations: (ctx) => [
|
|
{
|
|
name: ctx.plugin.themeStorageKey || THEME_STORAGE_KEY,
|
|
category: 'necessary',
|
|
purpose: T('Remembers the light or dark theme you chose.', 'Zapamiętuje wybrany motyw: jasny lub ciemny.'),
|
|
retention: UNTIL_CHANGED,
|
|
setBeforeConsent: true,
|
|
storage: 'localStorage',
|
|
vendor: SITE,
|
|
},
|
|
],
|
|
isEnabled: themeToggleOn,
|
|
key: 'theme',
|
|
label: A('cookieIntegrationTheme'),
|
|
},
|
|
{
|
|
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: A('cookieIntegrationAdmin'),
|
|
},
|
|
{
|
|
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: A('cookieIntegrationLocale'),
|
|
},
|
|
{
|
|
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: A('cookieIntegrationStats'),
|
|
},
|
|
{
|
|
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 name in one admin language (English when that language is missing). */
|
|
export function integrationLabel(integration: Pick<CookieIntegration, 'label'>, language = 'en'): string {
|
|
return textFor(integration.label, language) ?? ''
|
|
}
|
|
|
|
/** 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
|
|
}
|