PrivacyKit

CookieKit Component Reference

Public web component documentation for consent-dialog, consent-guard, and consent-missing.

Public Custom Elements

  1. <consent-dialog>
  2. <consent-guard>
  3. <consent-missing>
<consent-dialog>

Main entry component for consent UI and behavior.

Attributes
AttributeTypeDefaultDescription
variantstandard | modern | modeststandardVisual variant of the dialog.
expires-daysnumber180Cookie lifetime in days.
versionnumber0Consent schema version used for re-consent decisions.
localestringbrowser-derivedLocale override. Supported: en, no.
no-necessarybooleanunsetHides necessary section in UI.
no-preferencesbooleanunsetHides preferences section in UI.
no-analyticsbooleanunsetHides analytics section in UI.
no-marketingbooleanunsetHides marketing section in UI.
debugbooleanunsetEnables debug output.
demobooleanunsetDisables auto-open and uses demo subscription status.
openbooleanfalseControls open state.
Methods
openDialog(): Promise<void>
closeDialog(): Promise<void>
checkSubscriptionStatus(): Promise<void>
Named Slots
  1. dialog-title
  2. dialog-content
  3. necessary-content
  4. analytics-content
  5. marketing-content
  6. preferences-content
  7. read-more-title
  8. read-more-content
Example
<consent-dialog variant="standard" locale="en" version="1">
  <span slot="dialog-title">Your privacy choices</span>
  <span slot="analytics-content">We use analytics to improve product quality.</span>
</consent-dialog>
<consent-guard>

Conditionally renders content based on consent.

Attribute
AttributeTypeDefaultDescription
consentstringall categoriesConsent expression to evaluate.

Expression rules:

  1. Single category: analytics
  2. AND expression: analytics+marketing
  3. OR expression: analytics|marketing
  4. Omitted value: all categories required
Example
<consent-guard consent="marketing">
  <iframe
    title="YouTube video"
    data-src="https://www.youtube.com/embed/abc123"
    width="560"
    height="315"
    frameborder="0"
    allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
    allowfullscreen>
  </iframe>
</consent-guard>

Note: when using iframes, use data-src to avoid loading before consent.

<consent-missing>

Fallback content for blocked consent-guard content.

Attribute
AttributeTypeRequiredDescription
forstringyesId of the related <consent-guard>.
Example
<consent-guard id="analytics-guard" consent="analytics">
  <script type="text/plain" data-category="analytics" src="https://example.com/analytics.js"></script>
</consent-guard>

<consent-missing for="analytics-guard">
  Please accept analytics cookies to continue.
</consent-missing>

Script Setup

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

Framework Notes

  1. React: custom element typings are included in your distributed definition file.
  2. Vue 3: configure compilerOptions.isCustomElement for CookieKit tags.
  3. Angular: add CUSTOM_ELEMENTS_SCHEMA where custom elements are used.
  4. Svelte: no extra setup needed for runtime usage.