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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@convective/gdpr-consent

v1.2.0

Published

GDPR-compliant geo-targeted cookie consent for Next.js applications

Downloads

240

Readme

@convective/gdpr-consent

GDPR-compliant geo-targeted cookie consent for Next.js applications.

npm version License: MIT

Features

  • Geo-targeted consent (EU/EEA users only see banner)
  • CloudFront header support (AWS Amplify, CloudFront)
  • Equal Accept/Reject buttons (GDPR 2025 compliant)
  • 12-month consent expiration with audit trail
  • Privacy-first: configurable default when location unknown
  • Fully customizable styling and text
  • TypeScript support

Installation

npm install @convective/gdpr-consent

Quick Start

1. Wrap your app with ConsentProvider

// app/layout.tsx
import { headers } from "next/headers";
import { ConsentProvider, CookieBanner } from "@convective/gdpr-consent";

export default async function RootLayout({ children }) {
  const headersList = await headers();

  // Support env var override for testing, fallback to CloudFront header
  const countryCode = process.env.NEXT_PUBLIC_TEST_COUNTRY
    || headersList.get("cloudfront-viewer-country");

  return (
    <html>
      <body>
        <ConsentProvider
          countryCode={countryCode}
          config={{ defaultIsEU: process.env.NODE_ENV === "production" }}
        >
          <CookieBanner privacyPolicyUrl="/privacy" />
          {children}
        </ConsentProvider>
      </body>
    </html>
  );
}

2. Conditionally load analytics

"use client";

import Script from "next/script";
import { useConsent, shouldLoadAnalytics } from "@convective/gdpr-consent";

export function GoogleAnalytics() {
  const { isEU, consentStatus, isLoading } = useConsent();

  if (isLoading) return null;
  if (!shouldLoadAnalytics(isEU, consentStatus)) return null;

  return (
    <Script src="https://www.googletagmanager.com/gtag/js?id=G-XXXXX" />
  );
}

3. Add Cookie Preferences button (footer)

import { CookiePreferencesButton } from "@convective/gdpr-consent";

// Only shows for EU users
<CookiePreferencesButton className={styles.footerLink} />

Configuration

ConsentProvider Props

| Prop | Type | Required | Description | |------|------|----------|-------------| | countryCode | string \| null | Yes | ISO 3166-1 alpha-2 country code | | config | ConsentConfig | No | Configuration options |

ConsentConfig Options

<ConsentProvider
  countryCode={countryCode}
  config={{
    // List of country codes requiring consent (default: EU/EEA + UK)
    euCountries: ["DE", "FR", "GB", ...],

    // localStorage key (default: "gdpr_cookie_consent")
    storageKey: "my_cookie_consent",

    // Consent expiry in months (default: 12)
    expiryMonths: 6,

    // Default EU status when country code unavailable (default: true)
    // Set to false in development to hide banner during local testing
    defaultIsEU: process.env.NODE_ENV === "production",
  }}
>

CookieBanner Props

| Prop | Type | Default | |------|------|---------| | message | string | "We use cookies to analyze..." | | privacyPolicyUrl | string | "/privacy" | | privacyPolicyText | string | "Privacy Policy" | | acceptText | string | "Accept" | | rejectText | string | "Reject" | | className | string | - | | style | CSSProperties | - | | children | render function | - |

Custom Banner Rendering

<CookieBanner>
  {({ onAccept, onReject, privacyUrl }) => (
    <div className="my-custom-banner">
      <p>Custom message <a href={privacyUrl}>Privacy</a></p>
      <button onClick={onReject}>No thanks</button>
      <button onClick={onAccept}>OK</button>
    </div>
  )}
</CookieBanner>

useConsent Hook

const {
  isEU,           // boolean - is user in EU/EEA
  consentStatus,  // "pending" | "accepted" | "rejected"
  isLoading,      // boolean - still loading from localStorage
  grantConsent,   // () => void - accept cookies
  denyConsent,    // () => void - reject cookies
  resetConsent,   // () => void - show banner again
} = useConsent();

Geo-detection

This package reads the cloudfront-viewer-country header, available in:

  • AWS Amplify (since August 2024)
  • CloudFront distributions with geo headers enabled

Behavior by Environment

| Environment | Country Code | defaultIsEU | Banner Shown | |-------------|--------------|-------------|--------------| | Development | Not available | false | No | | Development | DE (via env var) | false | Yes | | Production | US (CloudFront) | true | No | | Production | DE (CloudFront) | true | Yes | | Production | Not available | true | Yes (privacy-first) |

Local Development Testing

To test the EU cookie banner in local development, add to .env.local:

# Simulate EU location for testing
NEXT_PUBLIC_TEST_COUNTRY=DE

Restart the dev server after changing. Remove or set to US to hide the banner.

GDPR 2025 Compliance

  • Prior consent required before loading analytics cookies
  • Equal prominence Accept/Reject buttons
  • Easy consent withdrawal (Cookie Preferences button)
  • Consent logging with timestamp
  • 12-month expiration (configurable)
  • No dark patterns

License

MIT