All systems nominal · edge p95 12ms v0.1.0GDPR · CCPA
Developer API

Gate your scripts. Ship in one line.

The Swift SDK exposes a minimal, zero-dependency API. Gate any callback on consent. Check state. Open the preference center. That's it.

Five methods. You'll use three.

Swift.onConsent(category, callback) MOST USED

Gate a callback on consent for a category. Fires immediately if consent is already granted. Queues otherwise, fires when user accepts.

// Load GA4 only after analytics consent
Swift.onConsent('analytics', () => {
  gtag('js', new Date());
  gtag('config', 'G-XXXXXXXXXX');
});

// Load Meta Pixel only after marketing consent
Swift.onConsent('marketing', () => {
  loadMetaPixel('YOUR-PIXEL-ID');
});
Categories: analytics · marketing · preferences
Swift.hasConsent(category) RETURNS boolean

Synchronous check. Use when you need to know the current state without waiting.

if (Swift.hasConsent('marketing')) {
  showPersonalizedContent();
} else {
  showGenericContent();
}
Swift.getConsent() RETURNS object | null

Returns the full consent state object, or null if no decision has been made yet.

// { necessary: true, analytics: true, marketing: false, preferences: false }
const state = Swift.getConsent();
Swift.openPreferences()

Opens the preference center programmatically. Use from footer "Cookie settings" links.

<!-- In your footer -->
<a href="javascript:Swift.openPreferences()">Cookie settings</a>
Swift.reset() RELOADS PAGE

Clears the consent cookie and reloads. Useful for testing and "forget me" flows.

Listen for consent changes.

// Fires whenever the user makes or changes a consent decision
document.addEventListener('swift:consent', (e) => {
  console.log(e.detail);
  // { necessary: true, analytics: true, marketing: false, preferences: false }
});

Wire your existing CMP.

// Cookiebot
window.__SWIFT_CONFIG__ = {
  upstream: { cmp: 'cookiebot', cbid: 'YOUR-DOMAIN-GROUP-ID' }
};

// OneTrust
window.__SWIFT_CONFIG__ = {
  upstream: { cmp: 'onetrust', apiKey: 'YOUR-API-KEY', orgId: 'YOUR-ORG-ID' }
};

// Generic endpoint
window.__SWIFT_CONFIG__ = {
  upstream: { endpoint: 'https://your-server.com/consent' }
};

Place this in a <script> tag before the Swift SDK loads. Consent decisions are relayed non-blocking — failures never affect the user experience.

← How it works See live demo →