Pre-built code blocks

Cookie banner that blocks trackers

Cookie box that loads no tracker before the visitor's yes

For when the answer to “It runs ad or analytics tracking (Meta Pixel, Google tag, TikTok Pixel) and needs to ask first” is yes.

A cookie box where no cookie, pixel or third-party request happens until the visitor says yes to that exact purpose, and an old yes never covers a purpose added later.

Skip the rebuild

You do not write this one. It arrives in your project as ordinary source you can read, change and keep, with its audit record and its caveats beside it.

  1. Download the Playground. It is free and runs on your own machine.
  2. Start a new app and tick “It runs ad or analytics tracking (Meta Pixel, Google tag, TikTok Pixel) and needs to ask first”.
  3. This block is written in, along with anything else you ticked.

Download the Playground See the other blocks

The mistake it removes

A tracker tag pasted into the page head runs before any banner can ask, so every visit is sent before consent. A banner that stores one global yes keeps honoring it after a new pixel is added, which is consent to something the visitor was never shown.

What you still have to do

A copied file cannot own your secrets, your host or your legal obligations. This is the part the block deliberately does not claim.

What lands in your project

vanilla

  • vanilla/consent.js

A classic script, served from your own domain at the path the stamper's scriptPath names. It reads the purpose list from the page, shows the box when there is no current answer, and loads each purpose's scripts only after its yes. window.consentKit.granted(id) and window.consentKit.reset() are there for your own code, and a consent-kit:granted event fires on document per purpose.

node

  • node/consent-stamp.js

Build time only. injectConsent(html, config) stamps the box, the purpose list and one first-party script tag into a page; privacySection(config) writes the cookie section of your privacy page, one paragraph per purpose plus the Change my answer button. validateConfig() refuses a list that would load anything early.

What you supply

Licensed MIT. It is a starting point, not a finished product.

Get it

Download the Playground See the other blocks

Nothing here is locked. The files are yours, in your folder, under a permissive license.

Questions

Is Cookie banner that blocks trackers audited?
No. No full audit has been run against this block yet, which is not the same as a pass.
What do I still have to do myself?
Do one keyboard pass and one screen-reader pass of the box on your own pages before launch. The box is a labeled region with a fieldset, a legend and real buttons, but the test drives it with clicks in headless Chromium, which is not a screen reader and is not your page.
How do I get this code?
Download the Playground, start a new app, and tick “It runs ad or analytics tracking (Meta Pixel, Google tag, TikTok Pixel) and needs to ask first”. The block is written into your project as ordinary source you can read and edit.

All pre-built code blocks · Learn to build from zero · The coding guide