C15T Logo

Callbacks

Learn how to use callbacks to respond to consent management events in both JavaScript and React applications.

Available callbacks

onBannerFetched

This callback fires when the consent banner is fetched. It is not invoked in offline mode.

Property
Types

onConsentSet

This callback is called when the consent is set.

Property
Types

onError

This callback is called when an error occurs.

Property
Types

Implementing Callbacks

src/App.tsx
import { 
  ConsentManagerDialog,
  ConsentManagerProvider,
  CookieBanner,
  type ConsentManagerOptions
} from '@c15t/react';

function App() {
  const options: ConsentManagerOptions = {
    mode: 'c15t', 
    backendURL: process.env.REACT_APP_C15T_URL,
    consentCategories: ['necessary', 'marketing'], // Optional: Specify which consent categories to show in the banner. 
    ignoreGeoLocation: true, // Useful for development to always view the banner.
    callbacks: {
      onBannerFetched(response) {
        console.log('Consent banner fetched', response);
      },
      onConsentSet(response) {
        console.log('Consent has been saved', response);
      },
      onError(response) {
        console.log('Error', response);
      },
    },
  };

  return (
    <ConsentManagerProvider options={options}>
      <div className="App">
        {/* Your application content */}
      </div>
      <CookieBanner />
      <ConsentManagerDialog />
    </ConsentManagerProvider>
  );
}

export default App;
Edit on GitHub

Last updated: May 12, 2025