Skip to content
Start free
Menu
Install with npm

Install with npm

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@1.3.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(). 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. 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.