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