Consenti Documentation
website·Indexed 30 days ago
https://consenti.devAn open-source, Apache 2.0 licensed Consent Management Platform (CMP) toolkit for GDPR and CCPA compliance. Includes technical guides for installing the UI Widget via npm, CDN, or ESM, and configuring backend storage with PostgreSQL, MongoDB, or MySQL. Supports TCF v2.3 and Google Consent Mode v2 integration.
What's inside Consenti
- Consenti is a self-hosted, open-source Consent Management Platform (CMP) toolkit (Apache 2.0 license) designed for GDPR and CCPA compliance. It provides a browser-first approach with an optional Node.js backend for durable storage, audit logs, and admin dashboarding. It features zero external runtime dependencies for both the UI and API components.
Conditionally load scripts and actions based on consent
UseConsentScriptto inject<script>tags andConsentActionto trigger callbacks (like SDK opt-ins) based on specific consent parameters.CategoryScriptandCategoryActionoperate on entire categories.BannerTriggerallows triggering the banner or modal from a DOM element. For a declarative approach, use<script type="text/plain" data-consenti-consent-script="...">and callscanConsentScripts().import { ConsentScript, ConsentAction, CategoryAction, CategoryScript, BannerTrigger } from '@consenti/ui' // Script based on specific cookie ID new ConsentScript({ cookieId: 'analytics_storage', widget, src: 'https://cdn.example.com/analytics.js' }) // Action based on specific cookie ID new ConsentAction({ id: 'analytics_storage', widget, onGrant: () => sdk.optIn(), onDeny: () => sdk.optOut() }) // Category-wide action new CategoryAction({ id: 'marketing', widget, onGrant: () => adSdk.enableAll(), onDeny: () => adSdk.disableAll() }) // Trigger modal from footer link new BannerTrigger({ widget, el: '#footer-cookie-settings', action: 'modal' })Compare Frontend-only vs Full-stack Deployment
Consenti can be deployed in two modes. You can start with frontend-only and migrate to full-stack by setting
api.enabled: truein the configuration.Feature Frontend-only With Backend (@consenti/api) Consent Storage Browser cookie / localStorage Server database (SQLite, MongoDB, PostgreSQL) Profile Management Defined in code Admin dashboard (no code changes needed) Audit Log No Yes (timestamped records with visitor ID) Multi-tenancy No Yes Setup Effort Single import & constructor call npm install @consenti/api + server mount Install Consenti UI Widget via CDN or ESM
For projects without a build step, Consenti can be loaded via a CDN (UMD) or directly as an ES Module in the browser.<!-- CDN / UMD --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@consenti/ui/dist/index.css" /> <script src="https://cdn.jsdelivr.net/npm/@consenti/ui/dist/index.umd.js"></script> <script> const { ConsentiSetup } = ConsentiUI new ConsentiSetup({ core: { regulation: 'gdpr' } }) </script>
<!-- ESM in Browser --> <script type="module"> import { ConsentiSetup } from 'https://esm.sh/@consenti/ui' new ConsentiSetup({ core: { regulation: 'gdpr' } }) </script>
Install and configure Consenti Backend API
The Consenti Backend API requires Node.js 22+ (Node 24 for built-innode:sqlite). It can be deployed as a standalone server, integrated into Express, Fastify, or as a Next.js Route Handler.// Fastify Integration import Fastify from 'fastify' import { createConsenti } from '@consenti/api' const fastify = Fastify() const consenti = createConsenti({ storage: { driver: 'node:sqlite', path: './consenti-data' }, auth: { mode: 'local', adminEmail: '...', adminPassword: '...' }, dashboard: true }) await fastify.register(consenti.fastifyHandler) await fastify.listen({ port: 3000 })Install Consenti UI Widget via npm
The recommended way to install the Consenti UI widget is via npm. Styles are auto-injected at runtime, so no separate CSS import is required by default.npm install @consenti/uiimport { ConsentiSetup } from '@consenti/ui' const widget = new ConsentiSetup({ compliance: { type: 'auto' }, // Geo-based detection (GDPR for EU, CCPA for CA, etc.) })Handle Global Privacy Control (GPC) for CCPA
WhenautoHonorGPC: 'strict'is configured, Consenti detects thenavigator.globalPrivacyControlsignal. If true, it automatically denies all cookies marked withlistenGpc: true, writes the consent record immediately without showing the banner, and storesgpc_detected: trueon the record.Set up Consenti Full-stack (Frontend + Backend)
To implement a full-stack consent solution, install the@consenti/apipackage for the server and@consenti/uifor the client. The backend provides an admin dashboard and REST API, while the frontend connects to this API to sync consent states.// Backend (Express) import express from 'express' import { createConsenti } from '@consenti/api' const app = express() const consenti = createConsenti({ storage: { driver: 'node:sqlite', path: './consenti-data' }, auth: { mode: 'local', adminEmail: 'admin@example.com', adminPassword: process.env.CONSENTI_ADMIN_PASSWORD!, }, dashboard: true, }) app.use(consenti.router) app.listen(3000) // Frontend import { ConsentiSetup } from '@consenti/ui' const widget = new ConsentiSetup({ compliance: { type: 'auto' }, api: { enabled: true, baseUrl: 'https://your-api.example.com' }, })Integrate TCF v2.3 and GPP for Programmatic Advertising
TCF v2.3 and GPP are required for publishers using IAB vendor ecosystems. Consenti provides the technical implementation, but the user must register their owncmpIdwith IAB Europe or MSPA. The widget must use thegeneral-privacy-consentcompliance type, and the server must be configured with thecmpId,cmpVersion, andpublisherCC(Country Code).// Widget configuration new ConsentiSetup({ compliance: { type: 'general-privacy-consent' }, api: { enabled: true, baseUrl: 'https://your-api.example.com' }, }) // Server configuration (@consenti/api) createConsenti({ compliance: { tcf: { enabled: true, cmpId: 9999, cmpVersion: 1, publisherCC: 'DE' }, }, })Implement GDPR Right to Erasure (Article 17)
To comply with the GDPR right to erasure, use the DELETE endpoint for a specific visitor. This removes all entries inconsent_records,consent_history, and thevisitorsrecord (including IP hash, UA hash, and geolocation).DELETE /consenti/api/v1/consent/:visitorIdEnable Google Consent Mode v2 in Consenti
Configure thegoogleConsentModeoption toenabled: truewithin theConsentiSetupconstructor. When enabled, Consenti automatically triggersgtag('consent', 'update', { ... })calls. The values foranalytics_storage,ad_storage,ad_user_data, andad_personalizationare dynamically derived from the user's actual consent choices.new ConsentiSetup({ compliance: { type: 'opt-in' }, googleConsentMode: { enabled: true }, })Configure Consenti UI Styling and CSS
Consenti provides several options for handling CSS to balance convenience and performance (avoiding Flash of Unstyled Content - FOUC).// To disable auto-injection and use your own styles new ConsentiSetup({ core: { disableCssTemplate: true } })