Consenti Documentation

website·Indexed 30 days ago

https://consenti.dev

An 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.

Tokens
4.2K
Snippets
25
Records
30
Agent score
3%

What's inside Consenti

  1. Consenti Product Overview

    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.
  2. Conditionally load scripts and actions based on consent

    Use ConsentScript to inject <script> tags and ConsentAction to trigger callbacks (like SDK opt-ins) based on specific consent parameters. CategoryScript and CategoryAction operate on entire categories. BannerTrigger allows triggering the banner or modal from a DOM element. For a declarative approach, use <script type="text/plain" data-consenti-consent-script="..."> and call scanConsentScripts().
    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' })
  3. 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: true in the configuration.

    FeatureFrontend-onlyWith Backend (@consenti/api)
    Consent StorageBrowser cookie / localStorageServer database (SQLite, MongoDB, PostgreSQL)
    Profile ManagementDefined in codeAdmin dashboard (no code changes needed)
    Audit LogNoYes (timestamped records with visitor ID)
    Multi-tenancyNoYes
    Setup EffortSingle import & constructor callnpm install @consenti/api + server mount
  4. 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>

  5. Install and configure Consenti Backend API

    The Consenti Backend API requires Node.js 22+ (Node 24 for built-in node: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 })
  6. 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/ui
    import { ConsentiSetup } from '@consenti/ui'
    
    const widget = new ConsentiSetup({
      compliance: { type: 'auto' }, // Geo-based detection (GDPR for EU, CCPA for CA, etc.)
    })
  7. Handle Global Privacy Control (GPC) for CCPA

    When autoHonorGPC: 'strict' is configured, Consenti detects the navigator.globalPrivacyControl signal. If true, it automatically denies all cookies marked with listenGpc: true, writes the consent record immediately without showing the banner, and stores gpc_detected: true on the record.
  8. Set up Consenti Full-stack (Frontend + Backend)

    To implement a full-stack consent solution, install the @consenti/api package for the server and @consenti/ui for 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' },
    })
  9. 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 own cmpId with IAB Europe or MSPA. The widget must use the general-privacy-consent compliance type, and the server must be configured with the cmpId, cmpVersion, and publisherCC (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' },
      },
    })
  10. 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 in consent_records, consent_history, and the visitors record (including IP hash, UA hash, and geolocation).
    DELETE /consenti/api/v1/consent/:visitorId
  11. Enable Google Consent Mode v2 in Consenti

    Configure the googleConsentMode option to enabled: true within the ConsentiSetup constructor. When enabled, Consenti automatically triggers gtag('consent', 'update', { ... }) calls. The values for analytics_storage, ad_storage, ad_user_data, and ad_personalization are dynamically derived from the user's actual consent choices.
    new ConsentiSetup({
      compliance: { type: 'opt-in' },
      googleConsentMode: { enabled: true },
    })
  12. 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
      }
    })