Pinning the browser SDK version
The npm package (@lucida-analytics/browser) is pinned by your lockfile like any dependency. This guide covers the classic script (lucida.js) that tag...
The npm package (@lucida-analytics/browser) is pinned by your lockfile like any dependency. This guide covers the classic script (lucida.js) that tag managers and plain <script> installs use, and the modules it loads lazily.
Versioned paths
A build (pnpm --filter @lucida-analytics/browser build) writes every bundle twice under dist/static/:
Path | Contents | Cache |
|---|---|---|
| one exact release, never changed |
|
| the latest release of that major | short ( |
|
| as the version folder |
Any 404 under /static/ is Cache-Control: no-store, so a release that is not published yet is never remembered as missing.
Serve dist/static/ from your CDN or reverse proxy (see the self-hosting reverse-proxy guide). The build refuses to run when LIB_VERSION in src/client.ts and the package version disagree, because lazily loaded modules are fetched from the loader's own version folder.
Pinned snippet
Pin an exact version and its hash:
<script>
window.lucidaQueue = window.lucidaQueue || [];
lucidaQueue.push(["init", "lc_pk_...", {
apiHost: "https://lc.example.com",
assetHost: "https://cdn.example.com",
modules: ["replay", "heatmaps"]
}]);
</script>
<script async src="https://cdn.example.com/static/v0.1.18/lucida.js"
integrity="sha384-PPVSd9WXHzh3I465pKZ3lJV8KG7PL9mRqizi1e0zeAjGosoBATQQfq8/UrrMLoNl" crossorigin="anonymous"></script>modules(classic script only) loads each named entry from<assetHost>/static/v<loader version>/<name>.jsbefore the client starts. Commands pushed meanwhile wait. A pinned loader therefore always gets matching modules. Names:replay,heatmaps,forms,toolbar,guides,inspector,experiments,early-access,consent.assetHostdefaults to the hostlucida.jsitself was loaded from, notapiHost(the capture host serves no static files). Set it only when the module files live elsewhere than the loader, as in the pinned snippet above. Hosted example: loaderhttps://<your app host>/lucida.js, moduleshttps://<your app host>/static/v0.1.18/replay.js.A module that fails to load is reported in the console and skipped. Capture still starts.
Lazily loaded modules are verified by the loader (from SDK 0.1.5): it reads
manifest.jsonfrom the same version folder, fetches each module, checks its SHA-384 with WebCrypto against the manifest and only then runs it. A module that differs, one the manifest does not list, or a page without WebCrypto (plain http) is refused with a console warning, and capture starts without it. With no manifest (an older deploy) modules load unchecked. Lazy chunks a module imports are not hashed separately; to hash everything, bundle the modules with the npm package.
Floating v<major> is convenient for trials. Production pages should pin an exact version, so a release never changes a page without a deploy.
Upgrading
Read the release notes (the upgrade guide).
Change the version in the
srcand replace theintegrityvalue from the newmanifest.json(lucida init --framework html(CLI 0.1.6 or later) prints the snippet for the CLI's pinned version).Deploy. Old version folders stay on the CDN, so cached pages keep working.
Renamed routes
When a proxy exposes the API under different paths (for example to avoid ad-block lists), rewritePath maps every request path on apiHost and flagsApiHost:
init("lc_pk_...", { apiHost: "https://example.com", rewritePath: (p) => p.replace(/^\/v1\//, "/a/") });The query string is kept. Requests to other hosts are untouched. Events sent through any host other than the Lucida default carry $lib_custom_api_host, so you can measure how much traffic goes through the proxy.