Install Lucida in a browser extension
Add Lucida to a Manifest V3 extension for Chrome, Edge or Firefox: installs, updates and uninstalls, popup and content-script events, feature flags.
@lucida-analytics/chrome-extension is for Manifest V3 extensions in Chrome, Edge, Brave, Opera and Firefox. The background worker owns the client. Popups, options pages, side panels and content scripts send to it with messages, so the whole extension shares one person, one queue and one set of flags.
1. Install
npm i @lucida-analytics/chrome-extensionBundle it with your extension (Vite, esbuild, webpack). The Chrome Web Store doesn't allow code loaded from a server, and nothing in the SDK does that.
Or let the CLI do steps 2 and 3: lucida init --host https://capture.lucidace.com in the extension's folder. It detects the setup and:
Setup | Key | Client | Wired into | Storage permission |
|---|---|---|---|---|
WXT ( |
|
| first line of |
|
Plasmo ( |
|
|
|
|
|
|
| the |
|
JSON files keep their key order. Running it twice changes nothing. Popups and content scripts still use connect() (step 4).
2. Manifest
{
"manifest_version": 3,
"permissions": ["storage"],
"background": { "service_worker": "background.js", "type": "module" }
}storage keeps the person's id and unsent events when Chrome stops the worker. Without it the SDK still works, but it warns in the console and every restart looks like a new person.
3. Background worker
import { createClient } from "@lucida-analytics/chrome-extension";
const lucida = createClient("lc_pk_YOUR_PUBLIC_KEY");Call it at the top level of the worker file. Chrome only delivers the install event to listeners added when the worker starts.
4. Popup, options page, side panel and content scripts
import { connect } from "@lucida-analytics/chrome-extension/page";
const lucida = connect();
lucida.capture("highlight_saved");
if (await lucida.isFeatureEnabled("new-toolbar")) showToolbar();On an extension page, connect() sends a $screen named after the page (popup.html). Every event says where it came from in $extension_context: popup, options, side_panel or content_script.
What you get
Event | When |
|---|---|
| First install |
| A new version is installed ( |
| The browser starts with the extension enabled |
| The extension is removed (see below) |
| An extension page opens |
Every event carries $extension_id, $extension_version (also $app_version), $os, $browser and $browser_version. Install and uninstall counts per version give you retention and churn per release.
Uninstalls
By default, removing the extension opens a short Lucida page in a new tab. It records $extension_uninstalled and tells the user the extension was removed. To show your own page (an exit survey), pass createClient(key, { uninstall: "https://example.com/bye" }). It opens with lucida_distinct_id and lucida_extension_version appended, so put the Lucida web snippet on it and call identify with that id. uninstall: false turns it off.
Privacy
Content-script events say nothing about the page the user is on.
tabUrl: "host"adds$host, andtabUrl: "url"adds$current_urltoo. Say so in your privacy policy and Web Store data disclosure before you turn it on.consent: { mode: "opt_in" }captures nothing untiloptIn(). AfteroptOut()the uninstall URL is cleared too.