PrivacyKit API Reference

This page documents the public JavaScript API used to read consent state, react to consent changes, and control the dialog flow from application code.

Table of Contents


Script setup

Load PrivacyKit once globally before calling any API methods.

<script type="module" src="https://cdn.privacykit.eu/privacykit/index.esm.js"></script>

Usage

All public access goes through the global window.PrivacyKit object, regardless of how the script loads.

const api = window.PrivacyKit;

if (api?.hasConsent('analytics')) {
  // analytics consent granted
}

const unsubscribe = api?.onConsentChanged(consent => {
  console.log('Consent changed', consent);
});

Window namespace

PrivacyKit exposes the full API on window.PrivacyKit.

window.PrivacyKit = {
  onReady,
  readConsent,
  hasConsent,
  onConsentChanged,
  openConsentDialog,
  onConsentDialogClosed,
  openPrivacyPolicyDialog,
  getSubscriptionStatus,
  subscriptionStatus,
};

Public methods

onReady

Subscribes to the privacykit:ready lifecycle event when the API becomes available.

onReady(callback: () => void): () => void
window.PrivacyKit?.onReady(() => {
  // Safe to call PrivacyKit API methods here
  const consent = window.PrivacyKit.readConsent();
  // ...
});

openConsentDialog

Opens the PrivacyKit dialog programmatically.

openConsentDialog(): void

onConsentDialogClosed

Subscribes to dialog close events.

onConsentDialogClosed(callback: () => void): () => void

openPrivacyPolicyDialog

Opens the Privacy Policy dialog programmatically in standalone mode, reusing the styling and slot content from the declared consent-dialog.

openPrivacyPolicyDialog(): void

getSubscriptionStatus

Returns the current subscription status for the domain. This is a read-only helper — subscription and billing are managed automatically by PrivacyKit via Paddle.

getSubscriptionStatus(): {
  status: string | null;
  billingInterval: string | null;
  subscriptionEnd: string | null;
  trailingEnd: string | null;
} | null