@katla.app/sdk/next entry point provides a pre-configured provider for Next.js that bundles the guard script injection, consent bridge, and all React hooks into a single "use client" import.
Prerequisites
- Next.js 13+ with the App Router
@katla.app/sdkinstalled (see SDK overview)
Setup
1. Add the provider to your root layout
ImportKatlaNextProvider directly in your root layout. Because the provider already includes a 'use client' directive, no wrapper file is needed — and children passed from a Server Component remain server-rendered.
KatlaNextProvider includes KatlaGuard and ConsentBridge automatically. To enable Google Consent Mode, pass the googleConsentMode prop:
Pages and components rendered as
{children} remain Server Components. The 'use client' boundary only affects the provider itself, not its children.KatlaNextProvider props
| Prop | Type | Default | Description |
|---|---|---|---|
siteId | string | — | Your site’s UUID (required) |
baseUrl | string | https://dist.katla.app | Override the CDN base URL |
locale | PolicyLocale | — | Default locale for policy documents (e.g., en-GB, de-DE, sv-SE). When set, all policy fetches use this locale unless overridden. |
debug | boolean | false | Enable console logging |
initialCookies | CookieData | null | — | Pre-fetched cookie data. When provided, useKatlaCookies() skips the runtime fetch. |
guardScript | string | — | Pre-fetched guard script content. When provided, the guard is inlined instead of fetched from the CDN. |
guard | boolean | true | Inject the cookie guard script that blocks non-consented cookies |
consentBridge | boolean | true | Connect window.KatlaConsent events to the React consent state |
googleConsentMode | boolean | false | Signal consent state to Google Analytics/Ads via Google Consent Mode v2 |
Using hooks
Import hooks directly from@katla.app/sdk/next. They work the same as in the React guide but are re-exported with the "use client" directive already applied.
| Hook | Description |
|---|---|
useKatlaCookies() | Fetch cookie data — returns { cookies, loading, error } |
useKatlaConsent() | Track consent state — returns { consent, onChange } |
useKatlaClient() | Access the underlying KatlaClient instance |
useConsentManager() | Combined consent state, cookie data, and actions — see React guide |
Components
All consent UI components are available from@katla.app/sdk/next and work identically to the React versions. They are unstyled and render semantic HTML with stable katla-* class names.
CookieBanner
A ready-to-use consent banner with accept, reject, and per-category customization.children render prop for a fully custom UI:
CookieCatalog
Displays your site’s cookies grouped by category.Building a consent banner
The fastest way to add a consent banner is with the<CookieBanner> component — it handles all the consent logic out of the box. For full control, use the useConsentManager hook or call window.KatlaConsent methods directly.
window.KatlaConsent is provided by the guard script that KatlaNextProvider injects automatically.Server-side rendering (SSR)
UsegetCachedCookies from @katla.app/sdk/next/server to fetch cookies in a Server Component and pass them to the provider. This avoids the client-side network request while keeping data fresh on every request.
initialCookies is provided, useKatlaCookies() returns the data immediately with loading: false and makes no network request.
getCachedCookies uses React’s cache() to deduplicate requests — even if multiple Server Components call it in the same render, only one fetch is made. It is a server-only import (@katla.app/sdk/next/server). Don’t import it in client components.Static cookies (build-time)
Use the Katla CLI to fetch cookie data at build time and bundle it as static data — no runtime fetch needed. This is ideal for static sites or when you want the fastest possible page load.CLI approach
Use the Katla CLI in your build pipeline:initialCookies is provided, useKatlaCookies() returns the data immediately with loading: false and makes no network request. getStaticGuardScript() reads the guard script from the .katla/ directory so it can be inlined instead of fetched from the CDN.
Debug mode
Passdebug to KatlaNextProvider to enable console logging:
Full example
A complete Next.js App Router setup with a cookie catalog and consent banner:- layout.tsx
- page.tsx
Examples
Dynamic SSR
Next.js App Router with server-side cookie fetching via
getCachedCookies.Build-time static
Next.js App Router using
katla pull for build-time cookie data.