Gathering detailed insights and metrics for react-cookie-manager
Gathering detailed insights and metrics for react-cookie-manager
Gathering detailed insights and metrics for react-cookie-manager
Gathering detailed insights and metrics for react-cookie-manager
react-native-cookie
A cookie manager module for react-native
nextjs-cookie-consent-manager
> This npm package is intended to add cookie consent management to your NextJS project with TypeScript, using Google Consent Mode technology.
react-native-cookies
Cookie manager for react native
react-manager-cookie
```bash npm i react-manager-cookie ``` #### useCookies - Hook to manage cookies
A powerful, customizable React component for cookie consent management with built-in tracking prevention. This component provides a modern, user-friendly way to obtain and manage cookie consent from your website visitors.
npm install react-cookie-manager
Typescript
Module System
Node Version
NPM Version
TypeScript (97.27%)
CSS (1.34%)
JavaScript (1.25%)
HTML (0.15%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
195 Stars
127 Commits
9 Forks
6 Branches
4 Contributors
Updated on Jul 10, 2025
Latest Version
3.7.2
Package Id
react-cookie-manager@3.7.2
Unpacked Size
369.44 kB
Size
78.38 kB
File Count
38
NPM Version
10.9.2
Node Version
23.10.0
Published on
Apr 04, 2025
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A powerful, customizable React component for cookie consent management with built-in tracking prevention. This component provides a modern, user-friendly way to obtain and manage cookie consent from your website visitors.
Get up and running quickly with React Cookie Manager:
1npm install react-cookie-manager 2# or 3yarn add react-cookie-manager
1import { CookieManager } from "react-cookie-manager"; 2import "react-cookie-manager/style.css"; 3 4createRoot(document.getElementById("root")).render( 5 <StrictMode> 6 <CookieManager> 7 <App /> 8 </CookieManager> 9 </StrictMode> 10);
The CookieManager component needs to wrap your entire application to properly manage cookie consent across all components and pages.
Take your GDPR compliance to the next level with CookieKit.io integration!
1import { CookieManager } from "react-cookie-manager"; 2 3function App() { 4 return ( 5 <CookieManager 6 cookieKitId="" // Get this from cookiekit.io 7 translations={{ 8 title: "Cookie Preferences", 9 message: "We use cookies to improve your experience.", 10 }} 11 > 12 <YourApp /> 13 </CookieManager> 14 ); 15}
When cookieKitId
is provided, React Cookie Manager will automatically:
Visit cookiekit.io to get started for free!
See React Cookie Manager in action and explore all its features in our interactive demo.
Unlike other cookie consent managers and React components, this component automatically disables tracking for Google Analytics, Facebook Pixel, and other tracking services. This is done by blocking the tracking scripts from loading. Therefore, you don't need to manually disable tracking, saving you hours of work.
React Cookie Manager automatically blocks embedded iframes that would otherwise load cookies without consent, such as:
When a user hasn't consented to the required cookies, these embeds are replaced with user-friendly placeholders that:
This ensures your site remains GDPR-compliant while providing a seamless user experience.
1npm install react-cookie-manager 2# or 3yarn add react-cookie-manager
The component requires its CSS file to be imported in your application. Add the following import to your app's entry point (e.g., App.tsx
or index.tsx
):
1import "react-cookie-manager/style.css";
1import { CookieManager } from "react-cookie-manager"; 2import "react-cookie-manager/style.css"; 3 4function App() { 5 return ( 6 <CookieManager 7 translations={{ 8 title: "Cookie Preferences", 9 message: "We use cookies to improve your experience.", 10 }} 11 onManage={(preferences) => 12 console.log("Cookie preferences:", preferences) 13 } 14 > 15 <YourApp /> 16 </CookieManager> 17 ); 18}
For Next.js applications, you'll need to use dynamic imports to prevent SSR of the cookie manager:
1"use client"; 2 3import dynamic from "next/dynamic"; 4 5const CookieManager = dynamic( 6 () => import("react-cookie-manager").then((mod) => mod.CookieManager), 7 { ssr: false, loading: () => null } 8); 9 10// In your Providers component or layout 11export function Providers({ children }: { children: React.ReactNode }) { 12 return ( 13 <CookieManager 14 showManageButton={true} 15 translations={{ 16 title: "Cookie Preferences", 17 message: "We use cookies to improve your experience.", 18 }} 19 displayType="banner" 20 theme="light" 21 > 22 {children} 23 </CookieManager> 24 ); 25} 26 27// In your page component 28import { useCookieConsent } from "react-cookie-manager"; 29 30export default function Home() { 31 const { showConsentBanner, detailedConsent } = useCookieConsent(); 32 33 return ( 34 <div> 35 <button onClick={showConsentBanner}>Manage Cookie Settings</button> 36 {detailedConsent && ( 37 <div> 38 Analytics:{" "} 39 {detailedConsent.Analytics.consented ? "Enabled" : "Disabled"} 40 Social: {detailedConsent.Social.consented ? "Enabled" : "Disabled"} 41 Advertising:{" "} 42 {detailedConsent.Advertising.consented ? "Enabled" : "Disabled"} 43 </div> 44 )} 45 </div> 46 ); 47}
1import { CookieManager } from "react-cookie-manager"; 2import "react-cookie-manager/style.css"; 3 4function App() { 5 return ( 6 <CookieManager 7 translations={{ 8 title: "Would You Like A Cookie? 🍪", 9 message: 10 "We value your privacy. Choose which cookies you want to allow. Essential cookies are always enabled as they are necessary for the website to function properly.", 11 buttonText: "Accept All", 12 declineButtonText: "Decline All", 13 manageButtonText: "Manage Cookies", 14 privacyPolicyText: "Privacy Policy", 15 }} 16 showManageButton={true} 17 privacyPolicyUrl="https://example.com/privacy" 18 theme="light" 19 displayType="popup" 20 cookieKitId="" // Optional: Enable CookieKit.io integration 21 onManage={(preferences) => { 22 if (preferences) { 23 console.log("Cookie preferences updated:", preferences); 24 } 25 }} 26 onAccept={() => { 27 console.log("User accepted all cookies"); 28 // Analytics tracking can be initialized here 29 }} 30 onDecline={() => { 31 console.log("User declined all cookies"); 32 // Handle declined state if needed 33 }} 34 > 35 <AppContent /> 36 </CookieManager> 37 ); 38}
1import { CookieManager, useCookieConsent } from "react-cookie-manager"; 2 3function CookieSettings() { 4 const { showConsentBanner, detailedConsent } = useCookieConsent(); 5 6 return ( 7 <div> 8 <button onClick={showConsentBanner}>Manage Cookie Settings</button> 9 {detailedConsent && ( 10 <div> 11 Analytics:{" "} 12 {detailedConsent.Analytics.consented ? "Enabled" : "Disabled"} 13 Social: {detailedConsent.Social.consented ? "Enabled" : "Disabled"} 14 Advertising:{" "} 15 {detailedConsent.Advertising.consented ? "Enabled" : "Disabled"} 16 </div> 17 )} 18 </div> 19 ); 20}
The floating cookie button provides a persistent, accessible way for users to manage their cookie preferences after they've made their initial choice. It appears as a small, animated cookie icon in the bottom-left corner of the screen.
1<CookieManager 2 enableFloatingButton={true} 3 theme="light" // or "dark" 4 // ... other props 5> 6 <YourApp /> 7</CookieManager>
The floating button automatically adapts to your chosen theme:
1// Light theme (default) 2<CookieManager 3 enableFloatingButton={true} 4 theme="light" 5> 6 <YourApp /> 7</CookieManager> 8 9// Dark theme 10<CookieManager 11 enableFloatingButton={true} 12 theme="dark" 13> 14 <YourApp /> 15</CookieManager>
The button inherits your color scheme:
The floating button is fully accessible:
Prop | Type | Default | Description |
---|---|---|---|
children | React.ReactNode | - | Your app components |
translations | TranslationObject | TranslationFunction | - | Translation object or i18n TFunction |
translationI18NextPrefix | string | - | i18next key prefix, e.g. "cookies." |
showManageButton | boolean | false | Whether to show the manage cookies button |
enableFloatingButton | boolean | false | Enable floating cookie button |
privacyPolicyUrl | string | - | URL for the privacy policy |
cookieKey | string | 'cookie-consent' | Name of the cookie to store consent |
cookieExpiration | number | 365 | Days until cookie expires |
displayType | 'banner' | 'popup' | 'modal' | 'banner' | How the consent UI is displayed |
position | 'top' | 'bottom' | 'bottom' | Position of the banner |
theme | 'light' | 'dark' | 'light' | Color theme |
disableAutomaticBlocking | boolean | false | Disable automatic tracking prevention |
blockedDomains | string[] | [] | Additional domains to block |
cookieKitId | string | undefined | Your CookieKit.io integration ID |
onManage | (preferences?: CookieCategories) => void | - | Callback when preferences are updated |
onAccept | () => void | - | Callback when all cookies are accepted |
onDecline | () => void | - | Callback when all cookies are declined |
classNames | CookieConsenterClassNames | - | Custom class names for styling |
React Cookie Manager provides extensive styling customization through the classNames
prop. You can override the default styling for each element of the cookie consent UI.
1<CookieManager 2 classNames={{ 3 // Main action buttons 4 acceptButton: 5 "bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded-lg", 6 declineButton: 7 "bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-4 rounded-lg", 8 manageButton: 9 "border-2 border-blue-500 text-blue-500 font-bold py-2 px-4 rounded-lg hover:bg-blue-50", 10 11 // Banner style (bottom of screen) 12 bannerContainer: 13 "bg-white/90 border-2 border-blue-200 shadow-xl rounded-xl", 14 bannerContent: "p-6 space-y-4", 15 bannerTitle: "text-lg font-bold text-blue-800", 16 bannerMessage: "text-sm text-gray-700", 17 18 // Popup style (bottom left corner) 19 popupContainer: "bg-white/90 border-2 border-blue-200 shadow-xl rounded-xl", 20 popupContent: "p-6 space-y-4", 21 popupTitle: "text-lg font-bold text-blue-800", 22 popupMessage: "text-sm text-gray-700", 23 24 // Modal style (center of screen) 25 modalContainer: "bg-black/50 backdrop-blur-sm", 26 modalContent: "bg-white p-8 rounded-xl max-w-lg mx-auto", 27 modalTitle: "text-xl font-bold text-gray-900", 28 modalMessage: "text-gray-600 my-4", 29 30 // Floating cookie button (appears after consent is given) 31 floatingButton: "bg-blue-500 text-white shadow-lg hover:bg-blue-600", 32 floatingButtonCloseButton: "bg-red-500 text-white", 33 34 // Manage Cookie UI elements 35 manageCookieContainer: "space-y-6", 36 manageCookieTitle: "text-xl font-bold text-blue-800", 37 manageCookieMessage: "text-gray-700", 38 manageCookieCategory: "border-b border-gray-200 pb-4", 39 manageCookieCategoryTitle: "font-bold text-gray-800", 40 manageCookieCategorySubtitle: "text-gray-600", 41 manageCookieStatusText: "text-xs text-gray-500 italic", 42 manageCookieToggle: "bg-gray-300", 43 manageCookieToggleChecked: "bg-green-500", 44 manageCancelButton: 45 "bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded", 46 manageSaveButton: 47 "bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded", 48 49 // Other elements 50 privacyPolicyLink: "text-blue-600 underline hover:text-blue-800", 51 poweredByLink: "text-gray-400 hover:text-gray-600", 52 }} 53> 54 {children} 55</CookieManager>
The classNames
prop is compatible with any CSS framework. Here are some examples:
1<CookieManager 2 classNames={{ 3 acceptButton: 4 "bg-green-500 hover:bg-green-600 text-white font-bold py-2 px-4 rounded", 5 declineButton: 6 "bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-4 rounded", 7 bannerContainer: "bg-white shadow-lg rounded-lg border border-gray-200", 8 }} 9> 10 {children} 11</CookieManager>
1<CookieManager 2 classNames={{ 3 acceptButton: "btn btn-success", 4 declineButton: "btn btn-danger", 5 manageButton: "btn btn-outline-primary", 6 bannerContainer: "card", 7 bannerContent: "card-body", 8 bannerTitle: "card-title", 9 bannerMessage: "card-text", 10 }} 11> 12 {children} 13</CookieManager>
The classNames are organized by component type:
acceptButton
: Style for the Accept/Allow cookies buttondeclineButton
: Style for the Decline/Reject cookies buttonmanageButton
: Style for the Manage Cookies buttonmanageCancelButton
: Style for the Cancel button in the manage preferences viewmanageSaveButton
: Style for the Save Preferences buttonbannerContainer
: Main container for the banner-style consent UIpopupContainer
: Main container for the popup-style consent UImodalContainer
: Main container for the modal-style consent UImanageCookieContainer
: Container for the manage preferences UIbannerContent
, popupContent
, modalContent
: Content containers for each display typebannerTitle
, popupTitle
, modalTitle
: Title elements for each display typebannerMessage
, popupMessage
, modalMessage
: Message elements for each display typemanageCookieTitle
: Title for the manage cookie preferences UImanageCookieMessage
: Description text in the manage preferences UImanageCookieCategory
: Container for each cookie categorymanageCookieCategoryTitle
: Title for each cookie categorymanageCookieCategorySubtitle
: Description for each cookie categorymanageCookieStatusText
: Status text showing consent status and datemanageCookieToggle
: Toggle switch for cookie categoriesmanageCookieToggleChecked
: Style applied to the toggle when checkedprivacyPolicyLink
: Style for the privacy policy linkfloatingButton
: Style for the floating cookie buttonfloatingButtonCloseButton
: Style for the close button on the floating cookie buttonpoweredByLink
: Style for the "Powered by CookieKit" linkThe component manages three categories of cookies:
1interface CookieCategories { 2 Analytics: boolean; 3 Social: boolean; 4 Advertising: boolean; 5}
The useCookieConsent
hook provides the following:
1interface CookieConsentHook { 2 hasConsent: boolean | null; 3 isDeclined: boolean; 4 detailedConsent: DetailedCookieConsent | null; 5 showConsentBanner: () => void; 6 acceptCookies: () => void; 7 declineCookies: () => void; 8 updateDetailedConsent: (preferences: CookieCategories) => void; 9}
The CookieManager component provides callback props that allow you to respond to user interactions with the consent UI:
Callback | Triggered when | Parameters |
---|---|---|
onAccept | User accepts all cookies | None |
onDecline | User declines all cookies | None |
onManage | User saves custom cookie preferences | preferences?: CookieCategories |
1<CookieManager 2 onAccept={() => { 3 console.log("All cookies accepted"); 4 // Initialize analytics tools 5 window.gtag?.("consent", "update", { analytics_storage: "granted" }); 6 }} 7 onDecline={() => { 8 console.log("All cookies declined"); 9 // Ensure tracking is disabled 10 window.gtag?.("consent", "update", { analytics_storage: "denied" }); 11 }} 12 onManage={(preferences) => { 13 console.log("Custom preferences saved:", preferences); 14 // Handle granular consent 15 if (preferences?.Analytics) { 16 // Enable analytics 17 } 18 if (preferences?.Advertising) { 19 // Enable ad personalization 20 } 21 }} 22> 23 {children} 24</CookieManager>
1import { default as i18next } from "i18next"; 2 3function App() { 4 return ( 5 <CookieManager 6 translations={i18next.t} 7 translationI18NextPrefix="cookies." 8 ... 9 /> 10 ) 11}
1// en.json 2{ 3 "cookies": { 4 "title": "Would You Like A Cookie? 🍪", 5 "message": "We value your privacy. Choose which cookies you want to allow. Essential cookies are always enabled as they are necessary for the website to function properly.", 6 "buttonText": "Accept All", 7 "declineButtonText": "Decline All", 8 "manageButtonText": "Manage Cookies", 9 "privacyPolicyText": "Privacy Policy" 10 } 11 //... 12}
All available translation keys and their default values:
1{ 2 // Main consent banner/popup/modal 3 title: "", // Optional title 4 message: "This website uses cookies to enhance your experience.", 5 buttonText: "Accept", 6 declineButtonText: "Decline", 7 manageButtonText: "Manage Cookies", 8 privacyPolicyText: "Privacy Policy", 9 10 // Manage consent modal 11 manageTitle: "Cookie Preferences", 12 manageMessage: "Manage your cookie preferences below. Essential cookies are always enabled as they are necessary for the website to function properly.", 13 14 // Essential cookies section 15 manageEssentialTitle: "Essential", 16 manageEssentialSubtitle: "Required for the website to function properly", 17 manageEssentialStatus: "Status: Always enabled", 18 manageEssentialStatusButtonText: "Always On", 19 20 // Analytics cookies section 21 manageAnalyticsTitle: "Analytics", 22 manageAnalyticsSubtitle: "Help us understand how visitors interact with our website", 23 24 // Social cookies section 25 manageSocialTitle: "Social", 26 manageSocialSubtitle: "Enable social media features and sharing", 27 28 // Advertising cookies section 29 manageAdvertTitle: "Advertising", 30 manageAdvertSubtitle: "Personalize advertisements and measure their performance", 31 32 // Status messages 33 manageCookiesStatus: "Status: {{status}} on {{date}}", // Supports variables 34 manageCookiesStatusConsented: "Consented", 35 manageCookiesStatusDeclined: "Declined", 36 37 // Buttons in manage modal 38 manageCancelButtonText: "Cancel", 39 manageSaveButtonText: "Save Preferences" 40}
You can override any of these translations by passing them in the translations
prop:
1<CookieManager 2 translations={{ 3 title: "Cookie Settings 🍪", 4 message: "We use cookies to improve your experience.", 5 buttonText: "Allow All", 6 manageButtonText: "Customize", 7 // ... override any other translations 8 }} 9> 10 <App /> 11</CookieManager>
When using i18next, make sure your translation files include all the keys under your chosen prefix:
1{ 2 "cookies": { 3 "title": "Cookie Settings 🍪", 4 "message": "We use cookies to improve your experience.", 5 "buttonText": "Allow All", 6 "declineButtonText": "Decline All", 7 "manageButtonText": "Customize", 8 "privacyPolicyText": "Privacy Policy", 9 "manageTitle": "Cookie Preferences", 10 "manageMessage": "Customize your cookie preferences below...", 11 "manageEssentialTitle": "Essential Cookies" 12 // ... include all other translation keys 13 } 14}
Then use it with the i18next translation function:
1import { useTranslation } from "react-i18next"; 2 3function App() { 4 const { t } = useTranslation(); 5 6 return ( 7 <CookieManager translations={t} translationI18NextPrefix="cookies."> 8 <YourApp /> 9 </CookieManager> 10 ); 11}
Contributions are welcome! Please feel free to submit a Pull Request.
MIT © Hypership
No vulnerabilities found.
No security vulnerabilities found.