0.1.8 • Published 8 months ago
@consentry/core v0.1.8
@consentry/core
Core consent management logic for Consentry SDK — handles preferences, script filtering, and integration with tools like Google Analytics.
✨ Overview
@consentry/core provides all the underlying logic required for consent management in your web applications. It helps filter scripts based on user preferences, manage consent storage via localStorage or cookies, and update analytics frameworks like Google Analytics.
This package is framework-agnostic and intended to be used alongside frontend-specific wrappers like @consentry/next.
📦 Installation
npm install @consentry/core🔧 Usage
1. Define fallback preferences
import { fallbackDefaults } from "@consentry/core";
console.log(fallbackDefaults);
// { functional: true, performance: false, advertising: false, social: false }2. Filter allowed scripts
import { getAllowedScripts } from "@consentry/core";
const scripts = getAllowedScripts(config, userPrefs, true);
// → returns only scripts the user has consented to3. Store & retrieve preferences
import { getConsentPreferences, setConsentPreferences } from "@consentry/core";
const currentPrefs = getConsentPreferences();
setConsentPreferences({ functional: true, performance: true, advertising: false, social: false });4. Send consent updates to Google Analytics
import { updateConsentSettings } from "@consentry/core";
updateConsentSettings("update", {
analytics_storage: "granted",
ad_storage: "denied",
});🧠 Types
ConsentCategory
"functional" | "performance" | "advertising" | "social"CookiePreferences
type CookiePreferences = Record<ConsentCategory, boolean>;ConsentScript
{
id: string;
category: ConsentCategory;
consentRequired?: boolean;
strategy?: "afterInteractive" | "lazyOnload" | "beforeInteractive";
src?: string;
content?: string;
noscript?: string;
vendor?: string;
default?: boolean;
}ConsentConfig
{
debug?: boolean;
defaults: CookiePreferences;
scripts: ConsentScript[];
}ConsentSettings (Google Analytics V4)
{
analytics_storage?: "granted" | "denied";
ad_storage?: "granted" | "denied";
ad_user_data?: "granted" | "denied";
ad_personalization?: "granted" | "denied";
}🚀 Coming soon
- ⚙️ Config validation with
defineConsentConfig() - 📚 Config file loader (
consent.config.ts) - 🔌 Integration hooks for third-party tools (FB Pixel, Hotjar, etc.)
📄 License
MIT — Copyright © 2025 Mustafa ONAL