Analytics script
BlockedAn inline script that counts visits. It stays as plain text until Analytics is allowed.
<script type="text/plain"
data-consent="analytics">
countVisits()
</script>Consent per purpose, withdrawal in one click, and English plus the 22 languages of the Eighth Schedule. No dependencies, and your site's CSS cannot break it.
English and all 22 languages of the Eighth Schedule to the Constitution of India. Urdu, Kashmiri and Sindhi are shown right to left. Users can also switch languages from inside the banner.
The interface texts come built in. Your purpose names and descriptions are your own: this demo translates them into Hindi only, so other languages show them in English.
Each change rebuilds the bar with your options. The panel on the right shows the saved consent and every event, as your code would receive them.
Mark a script or iframe with data-consent and consentbar holds it back. It runs as soon as the user allows that purpose, without a page reload. The three boxes below are real blocked elements on this page.
An inline script that counts visits. It stays as plain text until Analytics is allowed.
<script type="text/plain"
data-consent="analytics">
countVisits()
</script>A script that shows a personalised offer. It runs only after Marketing is allowed.
<script type="text/plain"
data-consent="marketing"
src="/js/offers.js"></script>An iframe from another site. Its src is set only after Embedded videos is allowed.
<iframe data-consent="video"
data-src="https://video.example/42">
</iframe>After withdrawing, to see the blocked state again.
Everything a consent notice needs, in one small package that works with any framework.
Users agree to each purpose separately. All switches start off, and "Reject all" is as easy to click as "Accept all".
A small "Privacy choices" button stays on the page. One click reopens the panel, so withdrawing is as easy as agreeing.
Each choice becomes a record with a time, notice version and language. Send records to your server as proof of consent.
Scripts and iframes marked with data-consent wait until the user allows their purpose.
Keyboard and screen reader support, focus handling in the panel, WCAG AA contrast in light and dark, and right-to-left scripts.
Plain HTML, WordPress, React, Next.js and Vue. It draws in a Shadow DOM, so your site's CSS cannot break it.
Install from npm, or add one script tag if you have no build tools.
// npm install consentbar
import { createConsentBar } from 'consentbar'
const bar = createConsentBar({
purposes: [
{ id: 'essential', title: 'Essential', description: 'Keeps you signed in and protects your account.', required: true },
{ id: 'analytics', title: 'Analytics', description: 'Counts visits so we can improve the site.', dataItems: ['Pages visited', 'Device type'] },
],
notice: {
fiduciaryName: 'Example Pvt Ltd',
privacyPolicyUrl: 'https://example.in/privacy',
contactEmail: 'grievance@example.in',
},
})
bar.hasConsent('analytics') // false until the user agrees
bar.on('change', ({ consent }) => console.log(consent.purposes))<script src="https://cdn.jsdelivr.net/npm/consentbar@1/dist/consentbar.global.js"></script>
<script>
const bar = ConsentBar.init({
purposes: [
{ id: 'essential', title: 'Essential', description: 'Keeps you signed in.', required: true },
{ id: 'analytics', title: 'Analytics', description: 'Counts visits.' },
],
notice: {
fiduciaryName: 'Example Pvt Ltd',
privacyPolicyUrl: '/privacy',
contactEmail: 'grievance@example.in',
},
})
</script>
<!-- Block a tracker until the user agrees -->
<script type="text/plain" data-consent="analytics" src="https://www.googletagmanager.com/gtag/js?id=G-XXXX" async></script>'use client'
import { useEffect } from 'react'
import { createConsentBar } from 'consentbar'
export function ConsentBar() {
useEffect(() => {
const bar = createConsentBar({
purposes: [
{ id: 'essential', title: 'Essential', description: 'Keeps you signed in.', required: true },
{ id: 'analytics', title: 'Analytics', description: 'Counts visits.' },
],
notice: { fiduciaryName: 'Example Pvt Ltd', privacyPolicyUrl: '/privacy', contactEmail: 'grievance@example.in' },
})
window.consentBar = bar
return () => bar.destroy()
}, [])
return null
}
// Add <ConsentBar /> to your root layout.The full guide, including consent records, notice versions and the CSS variables, is in the README.