Install Lucida on SvelteKit
Add the Lucida browser SDK to a SvelteKit app: package, root layout with only the key, CSP, optional proxy, consent and a first-event check.
@lucida-analytics/svelte gives stores for flags and consent, SPA page views, and an optional server handle. Server rendering never loads the browser SDK; replay starts in the browser after hydration.
1. Install
npm install @lucida-analytics/svelte @lucida-analytics/browserPut the public key in .env:
PUBLIC_LUCIDA_KEY=lc_pk_YOUR_PUBLIC_KEYlucida init --framework sveltekit --host https://capture.lucidace.com writes src/lib/lucida.ts and the env var, and tells you to import it in src/routes/+layout.svelte.
2. Init with the key
Create the client once, in the root layout, and let trackNavigation send the page views of client-side navigation (so turn the SDK's own off):
<!-- src/routes/+layout.svelte -->
<script>
import { afterNavigate } from "$app/navigation";
import { env } from "$env/dynamic/public";
import { createLucida, trackNavigation } from "@lucida-analytics/svelte";
const lucida = createLucida({ apiKey: env.PUBLIC_LUCIDA_KEY ?? "", options: { capturePageview: false } });
trackNavigation(afterNavigate, lucida.client);
</script>
<slot />No host option is needed on the cloud (default https://capture.lucidace.com). Add apiHost to options only when you self-host or use a reverse proxy.
createLucida returns { client, flags, flag(key), payload(key), consent, capture, destroy }. After sign-in call lucida.client.identify(user.id, { email }), and lucida.client.reset() on sign-out.
Flags without flicker need the server handle (lucidaHandle from @lucida-analytics/svelte/server, built on @lucida-analytics/edge); that is optional for analytics and is shown in the edge flags page.
3. Content Security Policy
script-src 'self';
connect-src 'self' https://capture.lucidace.com;The SDK is in your bundle, and it never uses eval. Through a proxy on your own domain, connect-src 'self' is enough. SvelteKit can set a CSP itself (kit.csp in svelte.config.js); put the same directives there. More for guides, experiments and the toolbar: Content Security Policy.
4. Reverse proxy (optional)
Set apiHost to a path on your domain and forward /v1/* to https://capture.lucidace.com: strip your prefix, pass bodies through untouched, cache nothing.
createLucida({ apiKey, options: { capturePageview: false, apiHost: "https://example.com/lc", uiHost: "https://lucidace.com" } });uiHost is needed because apiHost then no longer points at Lucida. The rule for nginx, Vercel and Cloudflare is in Serve Lucida from your own domain.
5. Consent
The SDK default is opt_out: it stores and sends before the visitor decides. For prior consent, add consent: { mode: "opt_in" } to options. Then nothing is stored or sent until you grant it from your banner:
lucida.consent.grant(); // lucida.consent.revoke() to withdraw; set(update) for categoriesFor the Cookie Munch banner see Cookie Munch consent. Defaults and regional rules: Consent by location.
6. Check the first event
Terminal:
lucida init --framework sveltekit --host https://capture.lucidace.com --project $LUCIDA_PROJECT_ID --verifywaits for a new event (needs an account key). Load a page of your app.App: the Install wizard (onboarding page) waits for the first event and tells you when it arrives.
If nothing arrives, look for Refused to connect in the console (CSP).
More
Quickstart (replay, groups, URL privacy), SDK pinning, all frameworks.