Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-consent-management-banner

faraasat0MIT1.1.13TypeScript support: included

Beautiful and Highly Customizable GDPR/ePrivacy React Consent and Cookie Management Library for React and Next.js

react, react component, nextjs, next.js, react consent, cookie, cookies, consent, cookie consent, cookie consent manager, cookie consent popup, cookie consent banner, consent management, consent manager, react consent management, react consent manager, react cookie manager, react cookie management, react cookie banner, react cookie management banner, react cookie manager banner, react consent management banner, react consent manager banner, banner, cookie banner, consent banner, react banner, cookie popup, cookie prompt, cookie modal, cookie disclaimer, cookie notification, cookie notice, cookie compliance, cookie preferences, cookie policy, cookie settings, consent settings, manage cookies, accept cookies, decline cookies, cookie categories, functional cookies, analytics cookies, marketing cookies, privacy, privacy notice, gdpr, gdpr compliance, eprivacy, eprivacy directive, ccpa, ccpa compliance, lgpd, cookie law, privacy law, data protection, data privacy, third-party cookies, react privacy tools, next.js consent banner, next.js cookie banner, nextjs cookie consent, nextjs gdpr

readme

🍪 Advanced Cookie Consent Banner

A fully configurable and lightweight cookie consent banner for React applications. Supports customizable layout, button text, and preference modal with persistent storage in localStorage. Full integration with GTag, Google Analytics and Adsense.

NPM JavaScript Style Guide npm download

react-consent-management-banner

📦 Installation

npm i react-consent-management-banner

yarn add react-consent-management-banner

pnpm i react-consent-management-banner

bun add react-consent-management-banner

⚙️ Demo

Access Demo at: Demo

Banner

Preferences

preferences

Integrated with Google Tag Assistant

googletag assistant

🚀 Features

  • ✅ Accept all cookies or reject non-essential ones
  • ⚙️ Fully configurable preference modal
  • 📍 Banner position (top / bottom)
  • 📌 Settings button position (top-left, top-right, bottom-left, bottom-right)
  • 🧠 Smart persistence via localStorage
  • 📜 Links to Cookie Policy, Privacy Policy, and Terms
  • ✨ Lightweight and easy to style

🧑‍💻 Usage

For React

import React from "react";
import { CookieConsent } from "react-consent-management-banner";

import "react-consent-management-banner/dist/style.css";

function App() {
  return (
    <div>
      <CookieConsent GA_TRACKING_ID="<YOUR_TRACKING_ID>" />
    </div>
  );
}

export default App;

For Next.js (Pages Router)

// _app.jsx|tsx
import React from "react";
import type { AppProps } from "next/app";
import { CookieConsent } from "react-consent-management-banner";

import "react-consent-management-banner/dist/style.css";

function MyApp({ Component, pageProps }: AppProps) {
  return (
    <React.Fragment>
      <Component {...pageProps} />

      <CookieConsent GA_TRACKING_ID="<YOUR_TRACKING_ID>" />
    </React.Fragment>
  );
}

export default MyApp;

For Next.js (App Router)

For App Router, we have to first export it from the client component and for this make a new file with any name and do this:

// layout.client.ts
"use client";

import { CookieConsent } from "react-consent-management-banner";

export { CookieConsent };
// layout.jsx|tsx
import React from "react";

import { CookieConsent } from "layout.client.ts";

import "react-consent-management-banner/dist/style.css";

function RootLayout({
  children,
}: Readonly<{
  children: React.ReactNode,
}>) {
  return (
    <html lang="en">
      <body>
        {children}

        <CookieConsent GA_TRACKING_ID="<YOUR_TRACKING_ID>" />
      </body>
    </html>
  );
}

export default RootLayout;

🛠 Configuration Options

You can pass a custom config prop to override defaults:

<CookieConsent config={customConfig} GA_TRACKING_ID="<YOUR_TRACKING_ID>" />

🔧 Config object structure

type CookieConsentConfig = {
  banner: {
    className?: string;
    title?: string;
    position?: "top" | "bottom";
    button: {
      acceptAlText?: string;
      rejectNonEssentialText?: string;
      preferencesText?: string;
    };
    links: {
      cookiePolicy?: IMoreLinks;
      privacyPolicy?: IMoreLinks;
      terms?: IMoreLinks;
      moreLinks?: Array<IMoreLinks>;
    };
  };
  preferences: {
    title: string;
    para?: string;
    className?: string;
    button: { savePreferencesText?: string; goBackText?: string };
    options: Array<IPreferenceOption>;
  };
  cookieFloatingButton: {
    position: "top-left" | "top-right" | "bottom-left" | "bottom-right";
    Component: React.JSX.Element | React.JSX.Element[] | React.ReactNode;
    show: boolean;
  };
  backgroundColor: string;
  linkColor: string;
  buttonBackgroundColor: string;
  textColor: string;
  onPreferencesChange?: (
    preferences: Record<string, boolean>,
    consentGiven: boolean
  ) => void;
  getConsentGiven?: () => void;
  getConsentPreferences?: () => void;
};

interface IMoreLinks {
  title: string;
  url: string;
}

🧠 How It Works

  • On initial load, if no preferences are stored, the banner is shown.
  • Clicking Accept All enables all cookie types.
  • Clicking Reject Non-Essentials enables only alwaysEnabled options (e.g., Necessary).
  • Preferences are stored in localStorage under the key cookiePreferences.
  • A floating settings button appears after consent is given, allowing users to adjust preferences later.

🗂 Local Storage Structure

{
  "ad_personalization": true,
  "ad_storage": true,
  "ad_user_data": true,
  "analytics_storage": true,
  "functionality_storage": true,
  "necessary_storage": true,
  "personalization_storage": true,
  "security_storage": true
}

Only alwaysEnabled: true options are locked on and non-toggle-able.

❓FAQ

Q: Does this banner block cookies automatically?

A: No, it simply records preferences and send them to the GTag.

Q: Is it compliant with GDPR/CCPA?

A: It provides necessary UX components, but legal compliance depends on how you use stored preferences to enable/disable cookies.

Q: Can I add custom preference categories?

A: Yes!

🧑‍🎓 Credits

Developed with ❤️ by Farasat Ali Feedback and contributions welcome!

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.1.13 (2025-06-16)

Bug Fixes

1.1.12 (2025-06-10)

1.1.11 (2025-06-10)

1.1.10 (2025-06-10)

1.1.9 (2025-06-08)

Bug Fixes

1.1.8 (2025-06-08)

Bug Fixes

1.1.7 (2025-06-08)

Bug Fixes

1.1.6 (2025-06-08)

Bug Fixes

1.1.5 (2025-06-08)

Bug Fixes

  • issue A tag read consent state before a default was set (4bf5b09)

1.1.4 (2025-06-08)

1.1.3 (2025-06-08)

Bug Fixes

  • issue with custom preferences selection and gtag not available (4ec0b56)

1.1.2 (2025-06-08)

Bug Fixes

  • window not defined issue (a6514db)

1.1.1 (2025-06-08)

Bug Fixes

  • issue in handleSavePreferences not saving essentials on custom preference (e9b7f6a)

1.1.0 (2025-06-08)

Features

  • add Google Consent Mode integration (ede93b0)

1.0.36 (2025-06-07)

1.0.35 (2025-06-05)

1.0.34 (2025-06-05)

Bug Fixes

1.0.33 (2025-06-05)

1.0.32 (2025-06-05)

1.0.31 (2025-06-05)

Bug Fixes

1.0.30 (2025-06-05)

Bug Fixes

1.0.29 (2025-06-05)

Bug Fixes

1.0.28 (2025-06-05)

Bug Fixes

1.0.27 (2025-06-05)

1.0.26 (2025-06-04)

1.0.25 (2025-06-04)

1.0.24 (2025-06-04)

1.0.23 (2025-06-03)

1.0.22 (2025-06-03)

1.0.21 (2025-06-02)

1.0.20 (2025-06-02)

1.0.19 (2025-06-02)

1.0.19 (2025-06-02)

1.0.18 (2025-06-02)

Bug Fixes

1.0.17 (2025-06-02)

Bug Fixes

1.0.16 (2025-06-02)

Bug Fixes

1.0.15 (2025-06-02)

1.0.14 (2025-06-02)

1.0.13 (2025-06-02)

1.0.12 (2025-06-02)

1.0.11 (2025-06-02)

1.0.10 (2025-06-02)

1.0.9 (2025-06-02)

Bug Fixes

1.0.8 (2025-06-02)

1.0.7 (2025-06-02)

Bug Fixes

1.0.6 (2025-06-02)

Bug Fixes

1.0.5 (2025-06-02)

1.0.4 (2025-06-02)

Bug Fixes

1.0.3 (2025-06-02)