Skip to content
Start free
Menu
Install with npm

Install with npm

Last updated Oct 1, 2026

Add the capture runtime to a site that has its own build, and call the same public API the script tag exposes.

If your site has a build step, install the capture code as a dependency instead of loading it from the CDN. The public API is the same as the script tag's.

Add the package

Command
npm install --save-exact @tracelog/capture-web@2.1.0

The command installs an exact version: --save-exact stops npm writing a range into your manifest. Update it after reviewing the new release.

Initialise it

JavaScript
import TraceLog from "@tracelog/capture-web";

TraceLog.init({ key: "tl_pk_xxxxxxxxxxxxxxxxxxxxxxxxxx" });

The key is your project's browser key, from Installation in the project. It is public and only accepted from the origins your project allows. The server key is a different credential: never put it in code that runs in the browser.

JavaScript
TraceLog.consent.grant();

TraceLog.step("form_started");

TraceLog.conversion("lead", { identifier: lead.id });

Nothing is captured before consent.grant(). Call it when the visitor accepts, and on every page load while their consent stands: a grant is not remembered. Calls made before init are held, up to 100, and made once it runs. If you import the package lazily, what you call before the import resolves is yours to hold. The full signature of every member is in the SDK reference.

Endpoint

By default the capture code sends events to /v1/events on your own origin, for a site that proxies TraceLog behind its own domain. If you do not proxy, set the endpoint to https://api.tracelog.io/v1/events:

JavaScript
TraceLog.init({
  key: "tl_pk_xxxxxxxxxxxxxxxxxxxxxxxxxx",
  endpoint: "<the ingestion endpoint above>",
});

Verify it

Open Installation in the project, start the test from Open my site, and walk the declared path in the tab that button opens. TraceLog marks that tab as verification traffic. Accept your consent banner in it first: from then on the tab stays a test across your pages and through a payment that leaves your site and comes back. A conversion you complete in any other tab counts as real and reaches your figures.

The checklist ticks as TraceLog receives each event, so a local copy of your site that cannot reach TraceLog shows nothing. Check the installation on a deployed version of your website; staging works too. Traffic from a staging hostname you have declared is marked as staging and stays out of your analytics.