Skip to content
Getting StartedQuick start

Quick start for SvelteKit

Markdown
Loading…

A working cookie consent banner in about a minute: one CLI command detects your framework and writes the setup for you.

One command in your existing project. The CLI detects your framework, asks a few questions and writes the setup for you, including the stylesheet import that is easy to forget. It runs locally and collects no data.

Prefer to write the files yourself? Installation is the same result in three steps.

1. Run the CLI

npx @cookieyes/cli init

2. Answer the questions

  1. Framework: detected for you, just confirm.
  2. Backend mode: choose Cookie-only. The choice is stored in the visitor's browser and no server is needed. Pick Self-hosted only if you must keep a record on your own server; it then asks for the URL.
  3. Privacy regulation: GDPR for most sites, CCPA for California-style opt-out.
  4. Colour scheme: light, dark, or follow the system.
  5. Extra languages: English is always included.
  6. Confirm, and it installs the package.

To skip the questions, in a script, in CI or from an AI coding tool, pass the answers as flags. --yes takes the default for any question left:

npx @cookieyes/cli init --yes --regulation GDPR --no-install

npx @cookieyes/cli --help lists every flag.

3. Start your app

The banner appears at the bottom of the page. Click Accept All and reload: it stays away, and a small round button in the corner reopens the preferences dialog.

What it wrote

  • src/lib/cookieyes.ts (.js in a JavaScript project): the configuration.
  • src/hooks.server.ts: export const handle = cookieyesHandle(config), or cookieyesHandle(config) added to the sequence() of a handle you already have.
  • src/routes/+layout.server.ts: export const load = loadConsent.
  • src/routes/cookieyes/styles.css/+server.ts: the stylesheet route.
  • src/routes/+layout.svelte: your page wrapped in <CookieYesRoot {config} state={data.consent}>.
  • src/app.d.ts: the /// <reference types="@cookieyes/sveltekit" /> line.

With adapter-static there is no server to read requests: the CLI then writes no +layout.server.ts, renders <CookieYesRoot {config}> without state, and adds export const prerender = true; to the stylesheet route.

Files that already exist are left alone. If the CLI cannot add the handle, the load or <CookieYesRoot> to a file you already have, it prints the lines to paste under "Manual step needed". An existing +layout.server.ts is never changed: return ...loadConsent(event) from its load.

To change anything later, edit src/lib/cookieyes.ts: every option is on Configuration.

Common mistakes

The banner does not appear. You already chose in this browser. Delete the cookieyes-consent cookie and reload.

The banner is unstyled text. The stylesheet route src/routes/cookieyes/styles.css/+server.ts was removed or moved. Put it back, or set stylesHref on the handle to where it lives now.

loadConsent() found no event.locals.cookieyes in the server log. cookieyesHandle(config) is no longer in src/hooks.server.ts. Add it back.

"Manual step needed" was printed. Paste the printed lines into your layout or entry file. Nothing else is missing.

Next steps

  • Configuration: every option of src/lib/cookieyes.ts
  • Integrations: load Google Analytics, Meta Pixel and other tags only after consent
  • Styling: match the banner to your brand

On this page