Configuration for SvelteKit
Every option of initCookieYes(), grouped by what it changes.
src/lib/cookieyes.ts is the one place you configure CookieYes. mode is the only required option; everything else has a sensible default. The config is the same CookieYesConfig that initCookieYes() takes in the other packages.
import type { CookieYesConfig } from "@cookieyes/sveltekit";
export const config: CookieYesConfig = {
mode: "cookie-only",
regulation: "GDPR",
theme: { primaryColor: "#1863dc" },
};cookieyesHandle(config) in src/hooks.server.ts and <CookieYesRoot {config}> in src/routes/+layout.svelte both import this object, so the server and the browser run the same options. The config never travels in data: SvelteKit serialises what a server load returns, so loadConsent hands over only what the server read, and options that hold functions, such as integrations and callbacks, come from this module on each side.
Options
Handle options
Two options exist only in cookieyesHandle. Pass them next to the shared config:
import { cookieyesHandle } from "@cookieyes/sveltekit";
import { config } from "./lib/cookieyes";
export const handle = cookieyesHandle({ ...config, googleConsentMode: true });| Option | Default | What it does |
|---|---|---|
stylesHref | "/cookieyes/styles.css" | The path the stylesheet route is mounted at. The handle links the full stylesheet from there. |
googleConsentMode | not set | true, or Consent Mode options, adds Google's deny-by-default snippet right after <meta charset>, before any Google tag. See Google Consent Mode. |
The handle composes with your own: export const handle = sequence(cookieyesHandle(config), yourHandle), with sequence from @sveltejs/kit/hooks. A transformPageChunk of yours still runs.
Setup
| Name | Type | Default | Description |
|---|---|---|---|
moderequired | "cookie-only" | "self-hosted" | None | Where the choice is stored: "cookie-only" in a browser cookie only; "self-hosted" also sent to your server. |
regulationoptional | Regulation | None | Which privacy law applies: "GDPR" (opt-in) or "CCPA" (opt-out). Unset behaves as GDPR. Wins over region detection. |
regionoptional | RegionConfig | None | Optional geo-detection: choose the active regulation from the visitor's region instead of hardcoding one. |
Appearance
| Name | Type | Default | Description |
|---|---|---|---|
colorSchemeoptional | ColorScheme | "system" | Light, dark, or follow-the-OS theme mode for the banner and preferences dialog. |
themeoptional | ThemeConfig | None | Colours, corner radius and font for every CookieYes surface. |
Language
| Name | Type | Default | Description |
|---|---|---|---|
i18noptional | I18nConfig | None | Translations, active locale, and on-demand language loading. |
Storage and blocking
| Name | Type | Default | Description |
|---|---|---|---|
categoriesoptional | CategoryDef[] | built-in five | Your own consent-category taxonomy. Omit to get the built-in five (necessary, functional, analytics, performance, advertisement) unchanged. |
networkBlockeroptional | NetworkBlockerConfig | None | Block matching third-party network requests (fetch/XHR/sendBeacon) by category until consent is granted. |
googleConsentMatchoptional | "all" | "any" | "any" | When several categories map to one Google Consent Mode signal: "any" grants it if any of them is granted, "all" only if all are. |
apiUrloptional | string | None | Endpoint each consent record (ConsentPayload) is POSTed to, under mode: "self-hosted". A 2xx response confirms it; otherwise it is kept in the browser and sent again. |
apiKeyoptional | string | None | Sent as an Authorization: Bearer <apiKey> header on the apiUrl POST, if set. |
backendoptional | ConsentBackend | None | Custom persistence adapter (persist(payload)): full control over transport, headers, batching, or a non-HTTP destination. Resolve once the record is stored; throw or reject otherwise, and the SDK keeps it and sends it again. |
Callbacks
| Name | Type | Default | Description |
|---|---|---|---|
integrationsoptional | Integration[] | None | Ready-made, consent-gated third-party integrations (Segment, Meta, Google, more) built from a preset in @cookieyes/scripts. |
customStopHandlersoptional | StopHandler[] | None | Your own scripts' stop instructions, for anything without a built-in integration or preset. |
onConsentReadyoptional | ((state: ConsentSnapshot) => void) | None | Fires once, when the initial consent state is known. |
onConsentUpdateoptional | ((state: ConsentSnapshot) => void) | None | Fires on every saved change, for the life of the page, and cannot be unsubscribed. |
reloadOnRevokeoptional | boolean | false | Force a full page reload when consent is revoked, instead of relying on clean runtime stops. |
theme
Nine keys for colour, corner radius and font. Each is listed with its default on Theme tokens.
region
| Name | Type | Default | Description |
|---|---|---|---|
region.detectoptional | RegionDetector | None | Return the visitor's region synchronously: e.g. from a hosting header you already have. |
region.mapoptional | Record<string, Regulation> | None | Region → regulation mapping (your own). Matched most-specific first: "US-CA" is checked before "US". |
region.honorGpcoptional | boolean | true | Honour the browser's Global Privacy Control "do not sell/share" signal (a CCPA opt-out). |
region.strictestoptional | Regulation | "GDPR" | Regulation to apply when the region is unknown or detection fails. |
region.debugoptional | boolean | false | Log the region decision to the console at setup, for local debugging. |
On a page the server renders per request, the handle reads the region from the Vercel (x-vercel-ip-country, x-vercel-ip-country-region) or Cloudflare (cf-ipcountry) geo headers, and those headers are the only region source, for the banner and for the browser alike. A region.detect of yours is used only where the server reads nothing (a prerendered page, or <CookieYesRoot> rendered without state), once the page has loaded. Until then such a page shows the banner of the strictest regulation.
i18n
messages per language, locale, detectBrowserLanguage and loadLanguage. See Translations.
networkBlocker
rules for requests to block until a category is granted, plus onRequestBlocked and logBlockedRequests. Needs registerNetworkBlocker() called once in src/lib/cookieyes.ts, before <CookieYesRoot> starts the runtime. See Network blocking.
Choosing a privacy law: the regulation option
"GDPR" | "CCPA" | |
|---|---|---|
| Optional categories before the visitor chooses | Off, the visitor opts in | On, the visitor opts out |
| Banner buttons | Accept All, Reject All, Customise | Do Not Sell |
| Global Privacy Control | Not used | Honoured |
Set the strictest law your visitors fall under, "GDPR" for most sites, and ship it for everyone. If you set nothing, the banner behaves as under "GDPR". To choose per visitor, set region instead: it maps the visitor's country to a regulation. A manual regulation always wins over region, so set one or the other.
Under "CCPA", a browser that sends Global Privacy Control starts the visitor opted out until they choose; region.honorGpc: false turns this off. The signal never changes which banner shows. To read it yourself, readGpc() returns true while the browser is sending it, and every consent record carries it as gpc.
Under "CCPA", <CookieYesRoot /> renders <CookieOptOut /> for you, and so it does when region can resolve to "CCPA": Do Not Sell opens it.
Consent categories
Leave categories out and you get the built-in five: necessary (required), functional, analytics, performance and advertisement. To use your own list:
import type { CookieYesConfig } from "@cookieyes/sveltekit";
export const config: CookieYesConfig = {
mode: "cookie-only",
categories: [
{ id: "necessary", required: true, label: "Essential" },
{ id: "analytics", label: "Analytics", gcm: ["analytics_storage"] },
{ id: "marketing", label: "Marketing", gcm: ["ad_storage", "ad_user_data"] },
],
};Ids must be unique and contain no , or :, and one category must be required: true; otherwise the list is rejected with a console warning and the built-in five are used. Decide your ids early: adding, removing or renaming an id later makes every returning visitor choose again. Labels and descriptions can change freely.
Where the choice is stored
cookie-only keeps the visitor's choice in a browser cookie and makes no network requests. Start here.
self-hosted also sends each choice to your server as a consent record, so you can keep proof of it. See Self-hosted mode for what your server receives and how to store it.
Common mistakes
'apiUrl' does not exist in type 'CookieYesOfflineConfig'.
You set apiUrl or backend under mode: "cookie-only". Switch to "self-hosted" or remove them.
regulation is set manually, so region detection is ignored.
You set both regulation and region. Keep one.
A custom category does not appear.
Your categories list broke one of the rules above; the console warning says which. The built-in five are shown instead.
Next steps
- Translations: every text in every language, through
i18n - Theme tokens: what each
themevalue changes - Integrations: load Google Analytics, Meta Pixel and other tags only after consent