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 is called when the consent banner is fetched, it is not called when the banner is set to 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

Due to the nature of Next.js App Directory, we have to define callbacks to run in a client component.

app/layout.client.tsx
'use client';

import { ConsentManagerCallbacks } from '@c15t/nextjs/client';

export function ClientLayout() {
	return (
		<ConsentManagerCallbacks
			callbacks={{
				onBannerFetched(response) {
					console.log('Consent banner fetched', response);
				},
				onConsentSet(response) {
					console.log('Consent has been saved locally', response);
				},
				onError(response) {
					console.log('Error', response);
				},
			}}
		/>
	);
}

Info

Ensure you import this component inside the ConsentManagerProvider component in your app/layout.tsx file.

Edit on GitHub

Last updated: May 12, 2025