Callbacks
React to consent lifecycle events — initialization, consent changes, errors, and revocation reloads.
Callbacks let you run custom code at key points in the consent lifecycle. Define them in the provider's callbacks option, or register them dynamically via useConsentManager().
Configuration
Define callbacks in the runtime options:
Available Callbacks
onBannerFetched
Called when the consent banner data is fetched from the backend (or loaded from SSR data). The payload includes jurisdiction info, location data, and resolved translations.
onConsentSet
Called whenever consent preferences are saved - whether by user action (saveConsents()), automatic defaults, or on initialization when no jurisdiction is detected.
onError
Called when an error occurs during consent operations (e.g., API request failure). If no onError callback is provided, errors are logged to console.error.
onBeforeConsentRevocationReload
Called synchronously before the page reloads due to consent revocation. This is your last chance to run cleanup before the reload. Keep this callback fast - avoid async operations.
Dynamic Registration
Register or update callbacks at runtime using setCallback():