PrivacyKit API Referentie

Deze pagina beschrijft de openbare JavaScript-API om toestemming uit te lezen, op wijzigingen te reageren en de dialoog vanuit je applicatie te besturen.

Inhoudsopgave


Scriptconfiguratie

Laad PrivacyKit globaal voordat je API-methodes aanroept.

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

Gebruik

Alle publieke toegang verloopt via het globale object window.PrivacyKit, ongeacht hoe het script wordt geladen.

const api = window.PrivacyKit;

if (api?.hasConsent('analytics')) {
  // toestemming voor analytics verleend
}

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

Window-namespace

PrivacyKit stelt de volledige API beschikbaar op window.PrivacyKit.

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

Publieke methodes

onReady

Abonneert op het lifecycle-event privacykit:ready wanneer de API klaar is.

onReady(callback: () => void): () => void
window.PrivacyKit?.onReady(() => {
  // Hier kun je veilig PrivacyKit-API-methodes aanroepen
  const consent = window.PrivacyKit.readConsent();
  // ...
});

openConsentDialog

Opent de PrivacyKit-dialoog programmatisch.

openConsentDialog(): void

onConsentDialogClosed

Abonneert op sluit-events van de dialoog.

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

openPrivacyPolicyDialog

Opent de Privacy Policy-dialoog programmatisch in standalone-modus en hergebruikt de styling en slot-inhoud van de gedeclareerde consent-dialog.

openPrivacyPolicyDialog(): void

toggleComplianceMonitor

Schakelt de PrivacyKit Compliance Monitor in of uit. Wanneer ingeschakeld verschijnt er een zwevende actieknop in de hoek van de pagina waarmee je toegang krijgt tot het Monitor-dialoogvenster.

toggleComplianceMonitor(): void

getSubscriptionStatus

Retourneert de huidige abonnementsstatus voor het domein. Dit is een alleen-lezen helper — abonnement en facturatie worden automatisch door PrivacyKit beheerd via Paddle.

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