This page documents the public JavaScript API used to read consent state, react to consent changes, and control the dialog flow from application code.
Load PrivacyKit once globally before calling any API methods.
<script type="module" src="https://cdn.privacykit.eu/privacykit/index.esm.js"></script>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);
});
PrivacyKit exposes the full API on window.PrivacyKit.
window.PrivacyKit = {
onReady,
readConsent,
hasConsent,
onConsentChanged,
openConsentDialog,
onConsentDialogClosed,
openPrivacyPolicyDialog,
getSubscriptionStatus,
subscriptionStatus,
};Subscribes to the privacykit:ready lifecycle event when the API becomes available.
onReady(callback: () => void): () => voidwindow.PrivacyKit?.onReady(() => {
// Safe to call PrivacyKit API methods here
const consent = window.PrivacyKit.readConsent();
// ...
});Reads the current consent cookie and returns a normalized consent object.
readConsent(): {
analytics: boolean;
marketing: boolean;
preferences: boolean;
} | null
Evaluates consent for a single category or expression.
hasConsent(expression?: string): booleanSubscribes to consent updates and returns an unsubscribe function.
onConsentChanged(callback: (consent: {
analytics: boolean;
marketing: boolean;
preferences: boolean;
} | null) => void): () => void
Opens the PrivacyKit dialog programmatically.
openConsentDialog(): voidSubscribes to dialog close events.
onConsentDialogClosed(callback: () => void): () => voidOpens the Privacy Policy dialog programmatically in standalone mode, reusing the styling and slot content from the declared consent-dialog.
openPrivacyPolicyDialog(): voidReturns 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