Business
Cookie Consent Banner
A working banner that holds scripts, logs consent with a policy hash, and exports CSV.
Most cookie banners are decoration. They appear, they write a flag, and the analytics tag has already run before the visitor has read the first line. Consent has to happen before the script, which means the script cannot be a normal script tag.
The banner on this page is the one the snippet gives you, running live. Accept or reject by category and watch the held scripts release; every decision writes a row to localStorage with the timestamp, the banner version and a hash of the policy text, so you can show what a visitor agreed to and which wording they were shown. It is a client-side banner and log, not a certified consent management platform, and the copy says where that matters.
How to use it
- Edit the policy text and the version, and set the link to your own cookie policy.
- Copy the snippet and paste it before the closing body tag on every page, then change held scripts to type text/plain with a data-consent category.
- Test the banner on a page with an analytics tag held, accept, and check the tag fires once.
- Export the log as CSV if you need to keep a copy outside the visitor's browser.
Questions
Does this replace a certified CMP?
No, and it should not be described as one. A certified consent management platform signs consent signals for advertising vendors and is audited for it. This is a client-side banner, a blocking mechanism and a local log: enough for a small site collecting its own analytics, not enough where vendors require a TCF signal.
Where is the consent stored?
In localStorage in the visitor's browser, under the key given in the snippet. It does not follow them to another device or another browser, it is cleared if they clear site data, and it is not a server-side record. For a durable audit trail you have to send the log to your own backend, which this snippet deliberately does not do.
Why record a hash of the policy?
So you can show which wording was on screen when the visitor agreed. The hash is a fingerprint of the policy text, not a security hash. Change the text and the hash changes, which makes the old consent fail validation and the banner appear again, asking for a fresh decision.
Do blocked scripts hurt the site?
They delay analytics until consent, so early traffic is undercounted, and that is the point. Strictly necessary scripts are never blocked. Anything that sets a cookie for measurement or advertising should be held, including tags added later by a tag manager.