Browse documentation

Browser SDK

Install the framework-neutral browser SDK with npm or load the production script directly.

Install the package

Install the package and initialize it once in browser-only code.

pnpm add tracwell
TypeScript
import { createTracwell } from "tracwell";

const analytics = createTracwell({
  collectionMode: "private",
  projectKey: "tw_live_...",
});

The package is safe to import during server rendering. Call createTracwell() only after the document is available. See the framework guides for the correct mount point.

Install with a script

Add the script before the closing body tag or through your framework's script component.

HTML
<script
  defer
  src="https://collect.tracwell.app/script.js"
  data-project-key="tw_live_..."
  data-collection-mode="private"
  data-consent="granted"
  data-respect-do-not-track="true"
></script>

The script exposes window.tracwell. Use it to track custom events after the script loads.

Page views and routing

Tracwell records the initial page automatically. It also observes pushState, replaceState, and browser back or forward navigation, covering normal path-based SPA routers.

Hash-only changes are ignored and URL fragments are excluded. Call analytics.page() only when your application changes the meaningful page without updating browser history.

Do not add a router page-view hook for standard History API routing. Doing so records duplicate page views.