// Get consent for specific purpose
const hasAnalytics = window.zaraz.consent.get('analytics');
// Set consent for specific purpose
window.zaraz.consent.set({ analytics: true });
// Using zaraz-ts for conditional loading
import { ifConsentGranted } from 'zaraz-ts';
await ifConsentGranted('analytics', () => {
// Load analytics script
console.log('Analytics enabled');
});
Advanced (zaraz-ts)
// Using zaraz-ts for conditional loading
import { ifConsentGranted } from 'zaraz-ts';
await ifConsentGranted('analytics', () => {
loadAnalyticsScript();
});
// Using zaraz-ts debug function
import { debugConsentState } from 'zaraz-ts';
await debugConsentState();
// Test zaraz-ts features
import { getAllConsent, hasConsentBeenSet } from 'zaraz-ts';
const consent = await getAllConsent();
const isSet = await hasConsentBeenSet();
window.zaraz.consent.sendQueuedEvents();
// Clear consent storage and reload
localStorage.removeItem('demo_consent');
location.reload();
// Using zaraz-ts
import { getAllConsent } from 'zaraz-ts';
const consent = await getAllConsent();
console.log(consent);
Console Logs & Events
// Listen for consent events (traditional)
document.addEventListener('zarazConsentAPIReady', () => {
console.log('Zaraz Consent API is ready');
});
// Using zaraz-ts for consent changes
import { onConsentChange } from 'zaraz-ts';
const unsubscribe = onConsentChange((consent) => {
console.log('Consent updated:', consent);
});
// Global tools available in console
window.zarazConsentTools.debug();
window.zarazConsentTools.getAll();
📦 Simulated Loaded Scripts:
🛠️ Global Tools Enabled:
Open browser console (F12) and try: window.zarazConsentTools.debug()