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...

Embed
Preview of the card
<a href="https://lucidace.com/help/sdk-pinning"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/62f42d4d-c0ab-4b49-a328-1794dae87536/social-card.svg?v=3e7ae33eec8b" alt="Pinning the browser SDK version" width="600" height="315"></a>

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

static/v<version>/lucida.js (and replay.js, heatmaps.js, ...)

one exact release, never changed

Cache-Control: public, max-age=31536000, immutable

static/v<major>/...

the latest release of that major

short (max-age=300); never cache forever

static/v<version>/manifest.json

{version, files: {"lucida.js": "sha384-...", "<name>.js": "sha384-..."}} (keys are the file paths relative to static/v<version>/), for Subresource Integrity; published from 0.1.5 on, there is none for 0.1.1 to 0.1.4. The 0.1.5 manifest keys lazy modules as modules/<name>.js; 0.1.6 and later use <name>.js

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>.js before 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.

  • assetHost defaults to the host lucida.js itself was loaded from, not apiHost (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: loader https://<your app host>/lucida.js, modules https://<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.json from 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

  1. Read the release notes (the upgrade guide).

  2. Change the version in the src and replace the integrity value from the new manifest.json (lucida init --framework html (CLI 0.1.6 or later) prints the snippet for the CLI's pinned version).

  3. 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.

Updated