Cookie consent without the bloat.

A small TypeScript package for static sites and SPAs. It stores consent, blocks optional scripts, handles privacy-safe embeds, and keeps the UI maintainable.

Download package
0
runtime dependencies
4
consent categories
<20 KB
target bundle

Test the real package behavior.

Use the buttons, open preferences, and try the YouTube placeholder. The sample events below show what runs immediately and what waits for consent.

Consent state

Analytics script blocked

    Sample events

    These examples simulate the kind of code each category would run on a production page.

    Necessary Form protection and language preference are active immediately.
    Active
    Analytics Example page-view event waits for Analytics consent.
    Blocked
    Marketing Example conversion pixel waits for Marketing consent.
    Blocked

    YouTube placeholder

    The iframe is not created until the visitor grants external-media consent or chooses to load this video once.

    What each consent type means in practice.

    Necessary code runs immediately. Analytics and marketing examples stay blocked until the matching category is granted.

    Necessary

    Core site behavior: CSRF tokens, form validation, session state, language choice, and security checks.

    // Do not gate first-party form handling.
    document.querySelector('form')?.addEventListener('submit', saveLead);

    Analytics

    Page-view or event measurement with tools such as Plausible, Umami, or Google Analytics.

    <script type="text/plain" data-consent="analytics">
      loadPlausible();
    </script>

    Marketing

    Advertising and conversion tracking, for example Meta Pixel, Google Ads, or remarketing tags.

    Consent.whenGranted('marketing', () => {
      loadMetaPixel();
    });

    Drop it into production in four steps.

    This is the path you can follow for a plain HTML site. Frameworks use the same API; initialize it from a client-side entry.

    1

    Add the package files

    Use the built files directly or publish this folder as an npm package.

    <link rel="stylesheet" href="/consent-kit.css">
    <script type="module" src="/consent-boot.js"></script>
    2

    Initialize ConsentKit

    Increase the version when your policy or category purpose changes.

    import { Consent } from './consent-kit.js';
    
    Consent.init({
      version: 1,
      locale: 'en',
      expirationDays: 180,
      googleConsentMode: true
    });
    3

    Gate third-party scripts

    Do not load analytics, ads, pixels, maps, or media until the matching category is granted.

    <script type="text/plain" data-consent="analytics">
      loadGoogleAnalytics();
    </script>
    
    Consent.whenGranted('marketing', loadMetaPixel);
    4

    Add privacy-safe embeds

    YouTube uses a placeholder and upgrades to youtube-nocookie.com after consent.

    <div
      class="ck-youtube"
      data-video-id="VIDEO_ID"
      data-youtube-url="https://www.youtube.com/watch?v=VIDEO_ID"
      data-title="Product demo">
    </div>

    Should you track consent history?

    For a small static site, local storage is often enough for runtime behavior. If you need to prove consent later, keep a server-side audit log of changes, not only the latest browser state.

    Usually enough

    Store the latest consent in the browser with category values, timestamp, policy version, and expiration. This package does that by default.

    Add when needed

    Send `consentChanged` events to your backend if you need proof for regulated analytics, logged-in accounts, ad campaigns, or formal compliance evidence.

    Example backend payload

    window.addEventListener('consentChanged', (event) => {
      fetch('/api/consent-events', {
        method: 'POST',
        headers: { 'content-type': 'application/json' },
        body: JSON.stringify({
          consent: event.detail.consent,
          policyVersion: event.detail.consent.version,
          page: location.pathname
        })
      });
    });

    Use the package build or copy the source.

    The build produces an ES module, UMD bundle, CSS, and TypeScript declarations. For local testing, run the commands below from this workspace.