Install Lucida on Vue and Nuxt

Add the Lucida browser SDK to a Vue 3 app or a Nuxt 3 app: packages, plugin or module with only the key, CSP, optional proxy, consent and a first-event check.

Embed
Preview of the card
<a href="https://lucidace.com/help/install-vue-nuxt"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/5c143f4d-a17e-4a7a-8f84-310a351f6b5d/social-card.svg?v=3e7ae33eec8b" alt="Install Lucida on Vue and Nuxt" width="600" height="315"></a>

Vue 3.3 or later uses the @lucida-analytics/vue plugin. Nuxt 3.8 or later uses @lucida-analytics/nuxt, which wires that plugin for you. The browser SDK is only constructed where window exists, so server rendering never touches it.

1. Install

Vue (Vite):

npm install @lucida-analytics/vue @lucida-analytics/browser

Nuxt:

npm install @lucida-analytics/nuxt @lucida-analytics/vue @lucida-analytics/browser

lucida init --framework vue --host https://capture.lucidace.com (or --framework nuxt) writes the env var and an init module and prints the install command. The Vue key variable is VITE_LUCIDA_KEY.

2. Init with the key

Vue:

// src/main.ts
import { createApp } from "vue";
import { lucida } from "@lucida-analytics/vue";

createApp(App).use(lucida, { apiKey: import.meta.env.VITE_LUCIDA_KEY }).mount("#app");

Nuxt:

// nuxt.config.ts
import { lucidaModule } from "@lucida-analytics/nuxt";
export default defineNuxtConfig({
  modules: [[lucidaModule, { apiKey: "lc_pk_YOUR_PUBLIC_KEY" }]],
});

NUXT_PUBLIC_LUCIDA_API_KEY overrides the key per environment. With no key the Nuxt plugin installs an inert client, so the composables never throw.

No host option is needed on the cloud (default https://capture.lucidace.com). Add options: { apiHost: "..." } only for self-hosting or a reverse proxy.

Composables (auto-imported in Nuxt): useLucida(), useCapture(), useFlag(key), useConsent(). Call them below the plugin; without app.use(lucida, ...) they throw in Vue.

<script setup lang="ts">
import { useLucida, useCapture } from "@lucida-analytics/vue"; // Nuxt: no import needed
const lucida = useLucida();
const capture = useCapture();
// after sign-in: lucida?.identify(user.id, { email }); on sign-out: lucida?.reset();
</script>

3. Content Security Policy

script-src  'self';
connect-src 'self' https://capture.lucidace.com;

The SDK ships in your bundle, so 'self' covers it, and it never uses eval. Through a proxy on your own domain, connect-src 'self' is enough. More lines 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. In Nuxt a route rule does it:

// nuxt.config.ts
routeRules: { "/lc/**": { proxy: "https://capture.lucidace.com/**" } },
// and in the module options: options: { apiHost: "/lc", uiHost: "https://lucidace.com" }

The rule must strip the prefix, pass bodies through untouched and not cache. Requirements, and nginx, Vercel and Cloudflare versions: Serve Lucida from your own domain. uiHost is needed because apiHost then no longer points at Lucida.

The SDK default is opt_out: it stores and sends before the visitor decides. For prior consent, start in opt_in through the SDK options (Vue: options: { consent: { mode: "opt_in" } } in the plugin options; Nuxt: the same options in the module options). Then nothing is stored or sent until useConsent().grant().

const { grant, revoke, status } = useConsent();

useConsent() also has setConsent, optIn and optOut. For the Cookie Munch banner, see Cookie Munch consent. Defaults and regional rules: Consent by location.

6. Check the first event

  • Terminal: lucida init --framework vue --host https://capture.lucidace.com --project $LUCIDA_PROJECT_ID --verify (or --framework nuxt) waits 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.

Updated