{"name":"add-cookie-consent-banner","description":"Adds a consent banner that blocks analytics and ad scripts until the visitor accepts, and remembers that choice. Use this when the user wants a cookie banner, consent before tracking, a GDPR notice, or to keep trackers off until opt-in.","category":"frontend","tags":["consent","privacy"],"models":["any"],"proven":false,"passing_families":0,"model_testing":"Not yet model-tested; testing Jan 2027","url":"https://theskillvault.ai/skills/add-cookie-consent-banner","api_url":"https://theskillvault.ai/api/skills/add-cookie-consent-banner","raw_url":"https://theskillvault.ai/api/skills/add-cookie-consent-banner/raw","body":"# Add a cookie consent banner\n\nLoad trackers only after a real yes. The banner is the gate. It is not the privacy page. For the page text and a privacy-friendly analytics setup, use add-analytics-and-privacy-policy.\n\nThis is not legal advice. Rules depend on who visits and where you operate. If you are unsure, ask a lawyer before you rely on the banner.\n\n## When to use\n- Analytics, ads or a chat widget set cookies or send an identifier before the visitor chooses.\n- You need Accept and Reject, with the same visual weight.\n- The choice must survive a reload.\n\n## When not to use\n- The only measurement is a cookie-free tool whose vendor documents that it sets no tracking cookies. You may not need a banner. Still say so on the privacy page.\n- You need the privacy policy wording itself. That is the other skill.\n\n## Steps\n1. List scripts that are not required for the page to function: analytics, ads, session-replay, embedded marketing pixels. The sign-in cookie and the consent choice itself stay on.\n2. Render a banner with two buttons, Accept and Reject. Do not pre-tick a box. Do not load the optional scripts in the first paint.\n3. Save the choice in a first-party cookie or in local storage, with the date. Read it before you decide whether to inject a script.\n4. On Accept, then add the script tags. On Reject, leave them out. Reloading must not ask again and must not start the trackers after a reject.\n5. If you use Google tags, set consent to denied before any tag runs, and update it to granted only after Accept. Check the current consent API rather than copying an old snippet.\n6. Offer a way back, such as a \"Cookie settings\" link, so the visitor can change the choice.\n7. Link the banner to the privacy page. Keep the banner copy to one or two short sentences.\n8. Test in a fresh profile with the network panel. No tracker request appears until Accept. Reject stays quiet after reload.\n\n```tsx\n\"use client\";\nconst KEY = \"cookie-consent\";\n\nexport function CookieBanner({ onChoice }: { onChoice: (value: \"accept\" | \"reject\") => void }) {\n  const save = (value: \"accept\" | \"reject\") => {\n    localStorage.setItem(KEY, value);\n    onChoice(value);\n  };\n  return (\n    <div role=\"dialog\" aria-label=\"Cookie consent\">\n      <p>Optional analytics stay off until you accept.</p>\n      <button type=\"button\" onClick={() => save(\"reject\")}>Reject</button>\n      <button type=\"button\" onClick={() => save(\"accept\")}>Accept</button>\n    </div>\n  );\n}\n```\n\nMount the analytics script only when the saved value is `accept`.\n\n## Gotchas\n- A tag in the root layout runs before the banner exists. Put optional scripts behind the saved choice.\n- A \"continue\" click that counts as accept, with no reject, is not a choice. Give a real reject.\n- Blocking the script tag is not enough if another component still calls the tracker. Search the repo for the script URL.\n- Dark patterns (a tiny reject, a pre-selected accept) fail the point of the banner and may fail the rule that applies to you.\n\n## Safety\n- The consent value is personal data in some places. Store only the choice and the date, not a copy of the tracking id.\n- Do not send the visitor to a third-party script \"just to see if they would have consented\".\n\n## Portability\nWorks with any framework, or with plain HTML. If you use Next.js, Astro or a static host, the rule is the same: do not emit the tracker until Accept. A server-rendered page must not set analytics cookies before the choice.\n\n## Example prompt\n\"Add a cookie banner that blocks analytics and ads until Accept, with Reject just as easy, and remember the choice.\"\n\n## Done when\n- A fresh visit sends no analytics or ad request before a choice.\n- Reject keeps those requests off after reload.\n- Accept loads them, and a settings link can change the stored choice.\n\n---\nHouse original by TheSkillVault (CC-BY-4.0).","files":[],"license":"CC-BY-4.0","license_name":"CC BY 4.0","license_url":"https://creativecommons.org/licenses/by/4.0/","attribution":"From TheSkillVault, https://theskillvault.ai, CC BY 4.0","install":{"claude_code":"curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-cookie-consent-banner/raw' -o ~/'.claude/skills/add-cookie-consent-banner/SKILL.md'","cursor":"curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-cookie-consent-banner/raw' -o '.cursor/skills/add-cookie-consent-banner/SKILL.md'","agents":"curl -fsSL --create-dirs 'https://theskillvault.ai/api/skills/add-cookie-consent-banner/raw' -o '.agents/skills/add-cookie-consent-banner/SKILL.md'","mcp_url":"https://theskillvault.ai/mcp","cursor_mcp_deeplink":"cursor://anysphere.cursor-deeplink/mcp/install?name=theskillvault&config=eyJ1cmwiOiJodHRwczovL3RoZXNraWxsdmF1bHQuYWkvbWNwIn0%3D","mcp_config":{"mcpServers":{"theskillvault":{"url":"https://theskillvault.ai/mcp"}}}},"bundles":[],"tested_on":[{"family":"chatgpt","name":"ChatGPT","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"claude","name":"Claude","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"gemini","name":"Gemini","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"grok","name":"Grok","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"llama","name":"Llama","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"deepseek","name":"DeepSeek","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"mistral","name":"Mistral","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"qwen","name":"Qwen","outcome":null,"date":null,"source":null,"counts":false,"stale":false},{"family":"kimi","name":"Kimi K","outcome":null,"date":null,"source":null,"counts":false,"stale":false}],"proven_rule":{"threshold":5,"window_days":365,"computed_at":"2026-11-29T03:42:30.374Z"}}