0.1.20 • Published 7 months ago
@consentry/next v0.1.20
@consentry/next
React + Next.js integration for the Consentry consent manager. Provides a plug-and-play Consent Manager Provider and dynamic script loader based on user preferences.
✨ Overview
@consentry/next is the official Next.js wrapper for @consentry/core. It offers:
- ✅ A React Context provider for managing cookie consent
- ✅ Automatic script filtering and injection via
<Script /> - ✅ Google Analytics consent synchronization (
gtag) - ✅ Support for external
consent.configfiles
📦 Installation
npm install @consentry/next @consentry/core⚙️ Setup
1. Create a consent.config.ts file in your app root:
import { defineConsentConfig } from "@consentry/core";
export default defineConsentConfig({
debug: true,
defaults: {
functional: true,
performance: false,
advertising: false,
social: false,
},
scripts: [
{
id: "ga4",
category: "performance",
strategy: "afterInteractive",
src: "https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX",
vendor: "Google Analytics",
},
{
id: "fb-pixel",
category: "advertising",
content: "console.log('Facebook Pixel loaded')",
vendor: "Facebook",
}
]
});2. Wrap your app with the ConsentManagerProvider
// app/layout.tsx or _app.tsx
import { ConsentManagerProvider } from "@consentry/next";
export default function RootLayout({ children }) {
return <ConsentManagerProvider>{children}</ConsentManagerProvider>;
}3. Use the hook to manage preferences
import { useConsentManager } from "@consentry/next";
const { cookiePreferences, setCategoryConsent } = useConsentManager();
return (
<button onClick={() => setCategoryConsent("performance", true)}>
Enable Performance Cookies
</button>
);🧠 Features
✅ ConsentManagerProvider
- Initializes state from
localStorageor cookies - Applies default values from
consent.config.ts - Syncs changes to
gtag()for analytics/ads - Injects scripts using
<Scripts />
✅ useConsentManager() hook
Returns:
{
cookiePreferences,
setCookiePreferences,
setCategoryConsent,
hasConsentedTo,
hasConsentedOnce
}✅ <Scripts /> component
Automatically injects only allowed scripts based on config + preferences.
📄 License
MIT — Copyright © 2025 Mustafa ONAL
0.1.20
7 months ago
0.1.19
8 months ago
0.1.17
8 months ago
0.1.16
8 months ago
0.1.15
8 months ago
0.1.14
8 months ago
0.1.13
8 months ago
0.1.12
8 months ago
0.1.11
8 months ago
0.1.10
8 months ago
0.1.9
8 months ago
0.1.8
8 months ago
0.1.7
8 months ago
0.1.6
8 months ago
0.1.5
8 months ago
0.1.4
8 months ago
0.1.3
8 months ago
0.1.2
8 months ago
0.1.1
8 months ago
0.1.0
8 months ago