PrivacyKit API-reference

Denne side dokumenterer det offentlige JavaScript-API til at læse samtykke, reagere på ændringer og styre dialogen fra din applikation.

Indholdsfortegnelse


Scriptopsætning

Indlæs PrivacyKit globalt, før du kalder API-metoder.

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

Anvendelse

Al adgang går gennem det globale objekt window.PrivacyKit, uanset hvordan scriptet indlæses.

const api = window.PrivacyKit;

if (api?.hasConsent('analytics')) {
  // samtykke til analytics givet
}

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

Window-namespace

PrivacyKit eksponerer hele API'et på window.PrivacyKit.

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

Offentlige metoder

onReady

Abonnerer på hændelsen privacykit:ready, når API'et er klar.

onReady(callback: () => void): () => void
window.PrivacyKit?.onReady(() => {
  // Her kan du sikkert kalde PrivacyKit-API'et
  const consent = window.PrivacyKit.readConsent();
  // ...
});

openConsentDialog

Åbner PrivacyKit-dialogen programmatisk.

openConsentDialog(): void

onConsentDialogClosed

Abonnerer på hændelser, når dialogen lukkes.

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

openPrivacyPolicyDialog

Åbner privatlivspolitik-dialogen programmatisk i standalone-tilstand og genbruger styling og slot-indhold fra den deklarerede consent-dialog.

openPrivacyPolicyDialog(): void

toggleComplianceMonitor

Aktiverer eller deaktiverer PrivacyKit Compliance Monitor. Når den er aktiveret, vises en flydende handlingsknap i sidehjørnet og giver adgang til Monitor-dialogen.

toggleComplianceMonitor(): void

getSubscriptionStatus

Returnerer den aktuelle abonnementsstatus for domænet. Dette er en skrivebeskyttet hjælpefunktion — abonnement og betaling håndteres automatisk af PrivacyKit via Paddle.

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