@katla.app/sdk package gives you programmatic access to your site’s cookie data and consent state. Use it to build custom consent UIs instead of the default widget, or to integrate cookie data into your application.
Prerequisites
- A Katla account with a verified site
- At least one completed scan
- Node.js 18+
Installation
Creating a client
| Option | Type | Default | Description |
|---|---|---|---|
siteId | string | — | Your site’s UUID (required) |
baseUrl | string | https://dist.katla.app | Override the CDN base URL |
Client methods
| Method | Returns | Description |
|---|---|---|
getCookies() | Promise<CookieData> | Fetch all cookies grouped by category |
getManifest() | Promise<Manifest> | Fetch the site manifest with resource URLs |
getGuardScript() | Promise<string> | Fetch the guard script source as a string |
injectGuard() | Promise<void> | Inject the guard script into the current page |
onConsentChange(callback) | () => void | Listen for consent changes; returns an unsubscribe function |
getCookies
Returns cookie data for your site, grouped by category.injectGuard
Injects the cookie guard script into the page. The guard interceptsdocument.cookie writes and blocks non-consented cookies.
onConsentChange
Subscribes to consent state changes. The callback fires whenever the visitor updates their preferences.Constants
COOKIE_CATEGORIES
An array of all cookie category strings:Types
| Type | Description |
|---|---|
KatlaClient | Client instance returned by createKatlaClient |
KatlaClientOptions | Options for createKatlaClient |
CookieData | Cookie data response with site, cookies, and jsUrl |
CookieInfo | Individual cookie with name, domain, platform, description, etc. |
CookieCategory | 'functional' | 'personalization' | 'analytics' | 'marketing' | 'security' | 'unknown' |
ConsentState | Record<CookieCategory, boolean> — consent per category |
ConsentChangeCallback | (consent: ConsentState) => void |
Manifest | Site manifest with site and resources URLs |
KatlaConsentAPI | The window.KatlaConsent API shape (see JavaScript API) |
ConsentManagerState | Return type of the useConsentManager() hook |
ManageableCategory | 'personalization' | 'analytics' | 'marketing' | 'security' — categories the visitor can toggle |
CookieBannerProps | Props for the <CookieBanner> component |
CookieCatalogProps | Props for the <CookieCatalog> component |
Caching
Even without static cookies, the SDK caches intelligently:- Client-side (React):
getCookies()deduplicates in-flight requests. Multiple components mounting simultaneously share a single fetch. - Server-side (Next.js): Use
getCachedCookies()from@katla.app/sdk/next/server— it wraps React’scache()to deduplicate across Server Components in the same render pass.
Next steps
Static cookies
Pre-fetch cookie data at build time to eliminate runtime requests.
React guide
Use the SDK with React hooks and components.
Next.js guide
Integrate the SDK in a Next.js App Router project.