Lær, hvordan du styrer PrivacyKit fra JavaScript og integrerer det i populære frameworks. Inkluderer TypeScript-understøttelse og praktisk vejledning til React, Vue, Angular, Svelte og Next.js.
Brug window.PrivacyKit til at læse samtykke, tjekke samtykkeudtryk, åbne dialoger og lytte efter samtykkeændringer. Det er nyttigt, når din applikation har brug for programmatisk kontrol, f.eks. i React, Vue eller almindelig JavaScript.
const api = window.PrivacyKit;
api.onReady(() => {
const consent = window.PrivacyKit.readConsent();
const initialState = consent ? JSON.stringify(consent, null, 2) : "";
console.log(initialState);
});
api.onConsentChanged((consent) => {
const updatedState = consent ? JSON.stringify(consent, null, 2) : "";
console.log(updatedState);
});
function handleOpenConsentDialogBtnClick() {
api.openConsentDialog();
}
function handleOpenPrivacyPolicyDialogBtnClick() {
api.openPrivacyPolicyDialog();
}
function handleToggleComplianceMonitorBtnClick() {
api.toggleComplianceMonitor();
}
Forbedr udvikleroplevelsen med autocomplete, typesikkerhed og indbygget understøttelse af PrivacyKit web components.
I moderne tooling (Next.js / Vite / TypeScript 5+) skal .d.ts-filer uden for src inkluderes eksplicit for at blive opfanget af compileren.
{
"include": ["src", "types/**/*.d.ts"]
}
Framework-specifikke råd til at integrere PrivacyKit custom elements.
<consent-dialog> virker i Server Components — indsæt den direkte i dit layout.'use client'-komponent.