Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

cookie-consent

БесплатноБез исполняемых скриптовНе проверен

Implement GDPR and ePrivacy-compliant cookie consent: a banner with equal Accept and Reject buttons, per-category choices, stored consent records…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub

Об этом скилле

Cookie Consent

Overview

The ePrivacy Directive (implemented in national law; the UK has PECR) requires prior consent before storing or reading non-essential data on a user's device, and the GDPR defines what valid consent is. GDPR fines reach EUR 20 million or 4% of global annual turnover, whichever is higher; national regulators (CNIL, the Italian Garante, the Dutch AP and others) actively fine cookie banners that make rejecting harder than accepting.

Strictly necessary storage needs no consent: login session, CSRF token, shopping cart, load balancing, and a preference the user explicitly set (for example a language switch they just clicked). Everything else needs consent first: analytics, advertising, personalization, embedded third-party media.

This skill is engineering guidance, not legal advice; have counsel check the wording and your cookie list.

Category Examples Consent needed
Strictly necessary Auth session, CSRF token, cart No
Functional Remembered preferences not explicitly chosen, chat widgets Yes
Analytics Google Analytics 4, Mixpanel, Hotjar Yes
Marketing Meta Pixel, Google Ads, retargeting Yes

Instructions

Valid consent (GDPR Art. 4(11) and 7) is freely given, specific, informed, unambiguous and withdrawable. In practice:

  1. Inventory every cookie, local-storage key and third-party script by category (scan with a browser's devtools or a crawler).
  2. Block non-essential scripts until consent exists: no pre-ticked boxes, no "scroll means consent".
  3. Show "Accept all" and "Reject all" on the first layer with equal prominence, plus "Customize".
  4. Explain each category and link the privacy and cookie policies.
  5. Store a consent record: version, timestamp, choices, source. Let users reopen the settings and withdraw as easily as they gave consent (a persistent "Cookie settings" link in the footer).
  6. Re-ask when the policy version changes or after a fixed period (6 months is common; regulators such as the CNIL accept up to 13 months).

Consent store (shared by everything else)

// lib/consent.ts
export interface ConsentPreferences {
  functional: boolean;
  analytics: boolean;
  marketing: boolean;
}
export interface ConsentRecord {
  version: string;
  timestamp: string;
  preferences: ConsentPreferences;
  source: 'banner' | 'settings' | 'gpc';
}

export const CONSENT_VERSION = '2026-10-01';
const KEY = 'consent_v2';

export function getConsent(): ConsentRecord | null {
  try {
    const raw = document.cookie.split('; ').find((c) => c.startsWith(`${KEY}=`));
    return raw ? JSON.parse(decodeURIComponent(raw.slice(KEY.length + 1))) : null;
  } catch {
    return null;
  }
}

export function saveConsent(preferences: ConsentPreferences, source: ConsentRecord['source']): void {
  const record: ConsentRecord = { version: CONSENT_VERSION, timestamp: new Date().toISOString(), preferences, source };
  const maxAge = 60 * 60 * 24 * 180; // 6 months
  document.cookie = `${KEY}=${encodeURIComponent(JSON.stringify(record))}; max-age=${maxAge}; path=/; SameSite=Lax; Secure`;
  void fetch('/api/consent', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(record),
    keepalive: true,
  }).catch(() => {}); // best-effort audit trail
  applyConsent(preferences);
}

export function applyConsent(p: ConsentPreferences): void {
  window.gtag?.('consent', 'update', {
    analytics_storage: p.analytics ? 'granted' : 'denied',
    ad_storage: p.marketing ? 'granted' : 'denied',
    ad_user_data: p.marketing ? 'granted' : 'denied',
    ad_personalization: p.marketing ? 'granted' : 'denied',
  });
  if (p.analytics) loadScript('ga4', `https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GA_ID}`);
  // marketing pixels: load only when p.marketing is true, using the same loadScript helper
}

function loadScript(id: string, src: string): void {
  if (document.getElementById(id)) return;
  const s = document.createElement('script');
  s.id = id;
  s.async = true;
  s.src = src;
  document.head.appendChild(s);
}

Google Consent Mode v2 (default denied)

Put this inline in <head> before any Google tag. Since 2024, EEA advertisers using Google ads or measurement features must send all four signals (ad_storage, analytics_storage, ad_user_data, ad_personalization).

window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
window.gtag = gtag;
gtag('consent', 'default', {
  ad_storage: 'denied',
  analytics_storage: 'denied',
  ad_user_data: 'denied',
  ad_personalization: 'denied',
  wait_for_update: 500,
});
gtag('js', new Date());
gtag('config', 'G-4F7K2M9QXB');  // your GA4 measurement ID

GA4 does not store IP addresses, so the old anonymize_ip flag does nothing, and _gid/_gat are Universal Analytics cookies; GA4 sets _ga and _ga_ plus the measurement ID s

Полный SKILL.md на GitHub

Установить cookie-consent в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл cookie-consent?

Implement GDPR and ePrivacy-compliant cookie consent: a banner with equal Accept and Reject buttons, per-category choices, stored consent records, consent-gated analytics with Google Consent Mode v2, and Global Privacy Control. Use when adding a cookie banner, managing marketing consent, achieving GDPR compliance for EU users, or integrating consent with analytics platforms.

Как установить скилл cookie-consent?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл cookie-consent запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить cookie-consent с