Untitled

Callbacks let you run custom code at key points in the consent lifecycle. Define them in the provider or runtime callbacks option, or register them dynamically after initialization.

For analytics SDKs and other change-only integrations, prefer subscribeToConsentChanges() or onConsentChanged. Use onConsentSet when you want the broader lifecycle signal, including initialization, automatic defaults, and replay-aware registration.

Choose the Right Surface

SurfaceReplays when registered late?Fires on init / hydration / auto-grants?Best for
onBannerFetchedYes, via setCallback('onBannerFetched', ...) after initYesLogging resolved policy, location, and translations
onConsentSetYes, via setCallback('onConsentSet', ...)YesBroad lifecycle hooks, debugging, and integrations that want the latest full state regardless of how it was reached
onConsentChangedNoNoDeclarative change-only integrations
subscribeToConsentChanges()NoNoCanonical change-only subscriptions after mount

Info

Script.onConsentChange is a script-scoped lifecycle hook. It is not the global consent change API for analytics SDKs or other app-wide integrations.

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 c15t broadly settles consent state: store initialization, automatic defaults during init, explicit saves, and replay via setCallback('onConsentSet', ...).

onConsentChanged

Called only after an explicit saveConsents() or setConsent() that actually changes the saved consent state. It never fires on store creation, hydration, automatic grants, unchanged saves, or setCallback('onConsentChanged', ...).

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.