Callbacks
Learn how to use callbacks to respond to consent management events in both JavaScript and React applications.
Overview
Callbacks allow you to execute custom code in response to various consent management events. They provide a way to integrate consent management with your application's logic, analytics, and other features.
Available Callbacks
The following callbacks are available your the c15t config.
Callback Reference
onError
: Called when an API request fails.onConsentBannerFetched
: Called after successfully fetching the consent banner information.onConsentSet
: Called after successfully setting consent preferences.onConsentVerified
: Called after successfully verifying consent.
Offline Mode Callbacks
Some callbacks require a call to an endpoint meaning they will not work fully in offline mode.
onConsentBannerFetched
: Will always return a simulated response of true, unless consent is in local storage.onConsentSet
: Stores consent in local storage.onConsentVerified
: Will always return a simulated response of true, unless consent is in local storage.
Usage Examples
Callback Response Types
Callback responses are always of type ResponseContext<T>
.
Prop | Type | Default |
---|---|---|
data | ResponseType | null | - |
response | Response | null | - |
error | { message: string; status: number; code?: string | undefined; cause?: unknown; details?: Record<string, unknown> | null | undefined; } | null | - |
ok | boolean | - |
onConsentSet Data
The onConsentSet
callback receives consent preference details:
Prop | Type | Default |
---|---|---|
type | string | - |
preferences | Record<string, boolean> | - |
domain? | string | - |
onConsentVerified Data
The onConsentVerified
callback receives verification results:
Prop | Type | Default |
---|---|---|
type | string | - |
domain? | string | - |
preferences | string[] | - |
valid | boolean | - |
onConsentBannerFetched Data
The onConsentBannerFetched
callback receives banner information:
Prop | Type | Default |
---|---|---|
showConsentBanner | boolean | - |
jurisdiction | { code: string; message: string; } | - |
location? | { countryCode: string | null; regionCode: string | null; } | - |