Install Lucida on your site

Create a project, copy its keys, add the browser SDK, identify signed-in users, group accounts, reset on sign-out, turn on replay and respect consent.

Embed
Preview of the card
<a href="https://lucidace.com/help/quickstart"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/b6a5698c-ddf2-4ba7-8a99-a67192298644/social-card.svg?v=3e7ae33eec8b" alt="Install Lucida on your site" width="600" height="315"></a>

Lucida measures how people use your product: events, sessions, replays, heatmaps, flags and experiments. This page takes a signed-in web app from nothing to identified users, accounts, replay and consent.

Hosts

Host

Use it for

Keys

https://lucidace.com (API and app)

management and read APIs: projects, keys, settings, queries, the console

account keys and project secret keys (lc_sk_...)

https://capture.lucidace.com (capture)

events, feature flags, profiles, replay

public project keys (lc_pk_...) and secret project keys

Self-hosting: both are your own domains (the API host serves the app and /v1, the capture host is the gateway); substitute them everywhere below. YOUR_PUBLIC_KEY and $LUCIDA_SECRET_KEY stand for the keys from step 1, $LUCIDA_PROJECT_ID for your project's id (shown in Settings > Project).

Install by framework

Each framework has its own page with the install, init, CSP lines, proxy, consent and first-event check in one place: Next.js, React (Vite), Vue and Nuxt, SvelteKit, Astro, plain HTML and server Node. The rest of this page is the generic browser setup.

1. Create a project and find its keys

Sign up at the Lucida app and create an organization and a project. There are two paths:

  • In the app: /signup and /login offer Continue to sign in, which hands you to the hosted Atlas sign-in page (there is no email and password form in Lucida itself). After you sign in you land back in the app, which creates your first organization and default project.

  • Over the API: POST /v1/auth/signup answers 202: Lucida emails a confirmation link and the account stays unusable until you open it, so use a mailbox you can read. Then create the organization with POST /v1/orgs. An organization made this way starts with no project: the next step is POST /v1/orgs/{org_id}/projects (the default project is created only by the app's first-run flow). GET /v1/orgs/{org_id}/projects is empty until you do.

Every project starts with two keys, listed in Settings > Project > Keys (and by GET /v1/projects/{project_id}/keys):

  • Public key (lc_pk_...): safe to ship in browser and mobile code. This is what the SDK needs.

  • Secret key: for your servers (server SDKs, POST /v1/s2s/batch, backfills). Never put it in client code. The one made with the project has the capture scope only: it sends events and reads nothing. Mint another with explicit scopes to read or erase.

Scripts and the CLI use an account key instead; how you get your first one, and what a sandbox is, is in Account API keys.

The capture host (your apiHost) is shown next to them and in the Install wizard. To send events without an SDK, see Send events over HTTP.

2. Add the SDK: init or createClient

npm install @lucida-analytics/browser
import { init } from "@lucida-analytics/browser";

export const lucida = init("lc_pk_YOUR_PUBLIC_KEY");

The default host is https://capture.lucidace.com, so only the key is needed. Set apiHost for self-hosting or a reverse proxy.

Pick one entry:

  • init(key, config?, extraModules?) is the full client: events, autocapture, feature flags and experiments, and cross-domain linking. Use this unless you are size-constrained.

  • createClient(key, config?, modules?) is the bare core. You list every module yourself, for example createClient(key, cfg, [autocapture, flags]). @lucida-analytics/browser/core is the smallest build.

Both return the same client. Call it once, at app start, and keep the instance.

Or a script tag

For plain HTML, tag managers and site builders, load the classic script from your Lucida app host (the host that serves the console, not the capture host):

<script>
  window.lucidaQueue = window.lucidaQueue || [];
  lucidaQueue.push(["init", "lc_pk_YOUR_PUBLIC_KEY", {
    apiHost: "https://capture.lucidace.com",
    modules: ["replay", "heatmaps", "forms"]
  }]);
</script>
<script async src="https://lucidace.com/lucida.js"></script>

modules are fetched from https://lucidace.com/static/v<version>/<name>.js (for example .../static/v0.1.18/replay.js): the loader looks next to itself, so assetHost is only needed when you host the files elsewhere (SDK pinning). getReplayUrl() links to the same app host; with the npm package set uiHost: "https://lucidace.com".

Next.js (App Router)

Next.js needs a provider, a first-party /ingest rewrite and a request hook. All of it, with versions and the lucida init --framework next output, is on Install on Next.js. The other --framework ids are nuxt, sveltekit, astro, react-native, angular, vue, react, node, django, python, rails, ruby, laravel, php, go, flutter and html (see the CLI).

3. Identify users, group accounts, reset on sign-out

// After sign-in (and on every page load while signed in)
lucida.identify("user_123", { email: "ada@example.com", plan: "pro" }); // second argument: person properties
lucida.group("company", "acme-inc", { name: "Acme Inc", seats: 25 });   // type, key, group properties

// Any custom event
lucida.capture("exported_report", { format: "csv" });

// On sign-out: forget the person so the next visitor is not merged into them
lucida.reset();
  • identify(id, set?, setOnce?) links the anonymous browsing before sign-in to id. Use your own stable user id, not an email that can change.

  • group(type, key, props?) attributes later events to an account (B2B analytics, group filters).

  • reset(resetDeviceId?) clears the identity, session and group state; pass true to also mint a new device id.

  • capture(name, properties?) sends an event. Pageviews and clicks are already captured by autocapture (init).

In a single-page app, call identify when your auth state resolves and reset in your sign-out handler; pageviews follow route changes by themselves (capturePageview: "history" is the default behaviour for history routers; use "hash" for hash routers).

4. Turn on session replay

Replay is a separate import, so it only loads when you use it:

import { init } from "@lucida-analytics/browser";
import { replay } from "@lucida-analytics/browser/replay";

export const lucida = init("lc_pk_YOUR_PUBLIC_KEY", { apiHost: "https://capture.lucidace.com" }, [replay]);

Replay and heatmaps are off for every project until you enable them. Importing the module is not enough: the SDK reads GET /v1/config and stays idle (events carry $recording_status: "disabled" and $replay_disabled_reason: "remote_disabled") while session_recording is false. Turn them on in Settings > Project > Replay, or over the API:

curl -X PUT https://lucidace.com/v1/projects/$LUCIDA_PROJECT_ID/settings/sdk \
  -H "Authorization: Bearer $LUCIDA_SECRET_KEY" -H "Content-Type: application/json" \
  -d '{"session_recording": true, "replay_sample_rate": 1, "heatmaps": true}'

replay_sample_rate is the share of sessions recorded (0 to 1). The SDK config is cached, so a change can take about 60 seconds to reach GET /v1/config; the first page load after that records.

Other opt-in modules have their own entry points the same way: @lucida-analytics/browser/heatmaps, /forms, /guides, /experiments. Inputs are masked in replay by default, see Replay privacy.

A new project requires consent (consent_mode: "opt_in"): until the visitor consents nothing is written to cookies or storage and nothing is sent, so the first events appear only after a grant. A site that needs no consent turns it off with PATCH /v1/projects/{id}/settings/sdk {"consent_mode":"off"}. Otherwise, either:

  • use Cookie Munch and pass its adapter as a module, see Cookie Munch consent; or

  • call lucida.setConsent({ analytics: true, replay: true, marketing: false }) from your own banner. lucida.getConsentStatus() is pending until the visitor decides.

Read the decision with getConsentStatus(category?) or consentStatus(). Both answer pending, granted or denied; consentStatus() is the analytics decision only, the same as getConsentStatus() with no argument. Prefer getConsentStatus(category): it is the only one that can answer for replay or marketing.

State

getConsentStatus() / consentStatus()

getConsentStatus("replay")

getConsentStatus("marketing")

Before a decision

pending

pending

pending

After a full grant

granted

granted

granted

After a partial grant (analytics and replay, no marketing)

granted

granted

denied

After a deny

denied

denied

denied

While the decision is pending the SDK writes no lc_* cookie, localStorage or sessionStorage item. When a visitor denies (or later withdraws) consent it removes the lc_* items it stored earlier. The one exception is the decision itself (lc_consent_<key suffix>, a cookie by default): it has to stay so the choice is remembered and the banner is not shown again.

Consent by visitor location is in Consent by location.

Keep secrets out of URLs

Every URL the SDK records ($current_url, $referrer, $pageleave, the $initial_* person properties and the page address in replays) has the value of well-known sensitive query parameters replaced with <masked> by default: password, passwd, pwd, pass, token, access_token, refresh_token, id_token, secret, client_secret, state, session, api_key, apikey, key, auth, authorization, code, otp, email, ssn (any letter case). Add your own, mask campaign parameters or drop the #fragment with urlPrivacy:

init("lc_pk_YOUR_PUBLIC_KEY", { apiHost, urlPrivacy: { maskParams: ["session", "invite"], maskCampaignParams: true, stripHash: true } });

maskParams adds to the default list; it never replaces it. More in Replay privacy.

6. Check the first event

Open the Install wizard in the app; it waits for the first event and tells you when it arrives. From a terminal, lucida init --framework <id> --verify does the same (see Install by framework). If nothing shows up, see Content Security Policy and Installing Lucida on site builders. To lock the SDK version, see SDK pinning.

Then check consent on the live site: lucida doctor --site https://<your-site> --cookies --trackers loads the page as a new visitor and reports anything stored or any tracker loaded before a consent decision (expected: "nothing is stored and no known tracker loads before consent"). To test a server key and a payload without writing data, send the batch with "test": true: POST https://capture.lucidace.com/v1/batch {"api_key":"…","test":true,"batch":[…]} validates both and answers {"accepted":n,"rejected":[…],"stored":false}.

7. Read a person from your server

To read one person on each request (personalization, an agent tool), call the gateway's Profile API with a secret key that has the profiles:read scope:

curl https://capture.lucidace.com/v1/profiles/user_123 \
  -H "Authorization: Bearer $LUCIDA_SECRET_KEY"

A valid key without the scope gets 403; an unknown person gets 404. The management route GET /persons is for tools and exports, not per-request reads.

Updated