npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lliam.nan/c8c

v0.1.0

Published

The world's least annoying cookie consent banner - GDPR compliant, performant, and invisible

Readme

Cookie Consent

The world's least annoying cookie consent banner - GDPR compliant, performant, and invisible.

Features

GDPR Compliant - Meets all legal requirements ✅ Minimal & Non-intrusive - Clean design, doesn't block content ✅ Zero CWV Impact - No DOM manipulation during load, optimized for performance ✅ Granular Control - Users can choose specific cookie categories ✅ Easy Revocation - Users can change preferences anytime ✅ Next.js Optimized - Works with Server Components, App Router, and SSR ✅ TypeScript First - Full type safety ✅ No Dependencies - Lightweight, tree-shakeable

Installation

npm install cookie-consent
# or
pnpm add cookie-consent
# or
yarn add cookie-consent

Quick Start

1. Initialize (shadcn-style)

npx cookie-consent init

This creates a cookie-consent.json config and sets up directories.

2. Add the component

npx cookie-consent add

This copies the component files to your project.

3. Add to your layout

// app/layout.tsx
import { CookieConsent } from '@/components/cookie-consent/cookie-banner';

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <CookieConsent />
      </body>
    </html>
  );
}

Done! Your cookie banner is now live.

Pre-built Integrations

Add popular analytics and tracking tools with a single command:

# Google Tag Manager
npx cookie-consent add gtm

Available integrations:

  • gtm - Google Tag Manager (analytics category)

More integrations coming soon: GA4, Facebook Pixel, Plausible, PostHog

Usage

Basic Banner

import { CookieConsent } from '@/components/cookie-consent/cookie-banner';

<CookieConsent />

Custom Configuration

<CookieConsent
  position="top"
  showDetailsDefault={false}
  config={{
    cookieName: 'my_consent',
    cookieExpiry: 180,
    version: '1.0',
    onPreferencesSaved: (prefs) => {
      console.log('Consent saved:', prefs);
    },
  }}
/>

Settings Button (for footer/privacy page)

import { CookieSettings } from '@/components/cookie-consent/cookie-settings';

<CookieSettings buttonText="Manage Cookies" />

Google Tag Manager Integration

Use the pre-built GTM integration for automatic consent management:

// app/layout.tsx
import { GoogleTagManager } from '@/components/cookie-consent/integrations/gtm';

export default function RootLayout({ children }) {
  return (
    <html>
      <body>
        {children}
        <CookieConsent />
        <GoogleTagManager id="GTM-XXXXXX" />
      </body>
    </html>
  );
}

The GTM integration automatically:

  • Only loads after analytics consent is given
  • Prevents duplicate loading
  • Includes noscript fallback
  • Uses proper async loading

Conditional Scripts (Analytics, Tracking, etc.)

Load scripts only when user consents:

import { ConditionalScript } from 'cookie-consent';

// Google Analytics - only loads if analytics consent given
<ConditionalScript
  category="analytics"
  src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID"
/>

<ConditionalScript category="analytics">
  {`
    window.dataLayer = window.dataLayer || [];
    function gtag(){dataLayer.push(arguments);}
    gtag('js', new Date());
    gtag('config', 'GA_MEASUREMENT_ID');
  `}
</ConditionalScript>

Using the Hook

'use client';

import { useCookieConsent } from 'cookie-consent';

function MyComponent() {
  const { isAllowed, preferences, hasConsent } = useCookieConsent();

  useEffect(() => {
    if (isAllowed('analytics')) {
      // Initialize analytics
    }
  }, [isAllowed]);

  return <div>Analytics enabled: {isAllowed('analytics') ? 'Yes' : 'No'}</div>;
}

Server-Side Consent Checking

// app/layout.tsx (Server Component)
import { isServerAllowed } from 'cookie-consent/next/server';

export default async function RootLayout({ children }) {
  const analyticsAllowed = await isServerAllowed('analytics');

  return (
    <html>
      <body>
        {analyticsAllowed && <GoogleAnalyticsScript />}
        {children}
      </body>
    </html>
  );
}

API

Cookie Categories

  • essential - Always enabled, required for site function
  • functional - Enhanced features and personalization
  • analytics - Usage statistics and analytics
  • marketing - Advertising and tracking

CookieManager

import { CookieManager } from 'cookie-consent';

const manager = new CookieManager({
  cookieName: 'cookie_consent',
  cookieExpiry: 365,
  version: '1.0',
});

// Check consent
manager.hasConsent(); // boolean
manager.isAllowed('analytics'); // boolean
manager.getPreferences(); // CookiePreferences | null

// Manage consent
manager.acceptAll();
manager.rejectAll();
manager.savePreferences({ functional: true, analytics: false, marketing: false });
manager.revokeConsent();

GDPR Compliance Checklist

Informed consent - Clear description of each category ✅ Affirmative action - No pre-ticked boxes ✅ Accept/Reject options - Both clearly available ✅ Granular control - Per-category selection ✅ Freely given - No forced acceptance ✅ Easy revocation - CookieSettings component ✅ Prior blocking - Scripts only load after consent ✅ Essential exemption - Essential cookies always allowed

Performance

  • No CWV impact - Lazy loaded, doesn't block rendering
  • Minimal bundle - ~3KB gzipped
  • No external deps - Pure React + cookies
  • Optimized rendering - Only shows when needed
  • Server-safe - No hydration issues

License

MIT