Skip to main content

SDKs & Client Libraries

JavaScript Runtime SDK

The ConsentForge runtime is included via the <script> tag — no npm install required. The runtime exposes a global ConsentForge object with the following methods:

Loading the runtime

<script
src="https://cdn.consentforge.com/consentforge.min.js"
data-token="cf_live_YOUR_EMBED_TOKEN"
defer
></script>

JavaScript API

// Check consent for a category
ConsentForge.hasConsent('analytics') // → true | false
ConsentForge.hasConsent('marketing') // → true | false
ConsentForge.hasConsent('functional') // → true | false

// Get all current choices
ConsentForge.getChoices()
// → { necessary: true, analytics: true, marketing: false, functional: true }

// Open the Preference Center programmatically
ConsentForge.openPreferenceCenter()

// Show the banner again (e.g. after a policy update)
ConsentForge.showBanner()

// Listen for consent events
ConsentForge.on('consent:updated', (choices) => {
console.log('User updated consent:', choices);
// Push to dataLayer, CRM, etc.
});

ConsentForge.on('consent:ready', (choices) => {
// Consent state loaded from storage — fires on every page load
if (choices.analytics) {
initAnalytics();
}
});

// Inline Preference Center
ConsentForge.renderPreferenceCenterInline('#consent-preferences-container');

Events

EventPayloadDescription
consent:readychoices objectFired when consent state is loaded on page init
consent:updatedchoices objectFired when the user changes their choices
consent:accepted_allchoices objectUser clicked "Accept All"
consent:rejected_allchoices objectUser clicked "Reject All"

Management API — HTTP Examples

The Management API has no dedicated SDK — use standard HTTP clients in your backend language.

Node.js

const BASE = 'https://api.consentforge.com/api/v1';
const headers = {
'Authorization': `Bearer ${process.env.CONSENTFORGE_API_KEY}`,
'Content-Type': 'application/json',
};

// List properties
const res = await fetch(`${BASE}/properties`, { headers });
const { data } = await res.json();

// Get receipts for a property
const receipts = await fetch(`${BASE}/receipts?property_id=prop_abc&limit=100`, { headers });

Python

import requests, os

BASE = 'https://api.consentforge.com/api/v1'
session = requests.Session()
session.headers.update({
'Authorization': f"Bearer {os.environ['CONSENTFORGE_API_KEY']}",
'Content-Type': 'application/json',
})

# List properties
properties = session.get(f'{BASE}/properties').json()

# Export receipts
receipts = session.get(f'{BASE}/receipts', params={
'property_id': 'prop_abc',
'limit': 500,
}).json()

PHP (Laravel)

use Illuminate\Support\Facades\Http;

$client = Http::withToken(config('services.consentforge.api_key'))
->baseUrl('https://api.consentforge.com/api/v1');

// List properties
$properties = $client->get('/properties')->json('data');

// Create a webhook
$webhook = $client->post('/webhooks', [
'property_id' => 'prop_abc',
'url' => 'https://your-app.com/webhooks/consentforge',
'events' => ['consent.created', 'consent.updated'],
])->json();

Google Tag Manager Integration

For GTM deployments, ConsentForge pushes consent state to the dataLayer automatically:

// Available in GTM as dataLayer variables
window.dataLayer.push({
event: 'consent_update',
consent_analytics: 'granted', // or 'denied'
consent_marketing: 'denied',
consent_functional: 'granted',
});

Use this with GTM's built-in Consent Mode template or custom triggers.


Community Libraries

info

Official SDKs are planned. If you've built a ConsentForge SDK for your language, let us know.

LanguagePackageMaintained by

Changelog

SDK and API updates are documented in the Changelog.