npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@trace-x/sdk-browser

v0.1.6

Published

TraceX Analytics SDK for Browser

Readme

TraceX JavaScript SDK

A lightweight browser analytics SDK for tracking user behaviour, page views, and errors in single-page applications.

Installation

npm / yarn / pnpm

npm install @trace-x/sdk-browser
# or
yarn add @trace-x/sdk-browser
# or
pnpm add @trace-x/sdk-browser

CDN (ESM)

<script type="module">
  import { analytics } from "https://cdn.jsdelivr.net/npm/@trace-x/sdk-browser/dist/tracex.esm.js";
  analytics.init({ endpoint: "https://your-tracex-server" });
</script>

Quick Start

import { analytics } from "@trace-x/sdk-browser";

// Initialize once (e.g. in main.ts / index.ts)
analytics.init({
  endpoint: "https://your-tracex-server",
  appVersion: "1.0.0",
  autoPageView: true, // automatically track page_view on navigation
  autoError: true, // automatically capture unhandled errors
});

// Identify the logged-in user
analytics.identify("user_123");

// Track a custom event
analytics.track("button_click", {
  button: "buy",
  page: "/trading",
  symbol: "AAPL",
});

// Track a page view manually (if autoPageView is false)
analytics.trackPageView({ section: "dashboard" });

// Force-flush before a critical navigation (awaitable)
await analytics.flush();

// Clean up (removes event listeners, stops timers)
analytics.destroy();

React Integration

// src/analytics.ts
import { analytics } from "@trace-x/sdk-browser";

analytics.init({
  endpoint: import.meta.env.VITE_TRACEX_ENDPOINT,
  appVersion: import.meta.env.VITE_APP_VERSION,
  autoPageView: true,
  autoError: true,
});

export { analytics };

// src/main.tsx
import "./analytics";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";

createRoot(document.getElementById("root")!).render(
  <StrictMode>
    <App />
  </StrictMode>,
);
// Track events from a component
import { analytics } from "./analytics";

function BuyButton({ symbol }: { symbol: string }) {
  return (
    <button onClick={() => analytics.track("trade.buy_clicked", { symbol })}>
      Buy {symbol}
    </button>
  );
}

Configuration Reference

| Option | Type | Default | Description | | ---------------- | ------------- | --------- | ------------------------------------------------- | | endpoint | string | — | Required. TraceX server base URL | | appVersion | string | "" | Application version tag | | platform | string | "web" | Platform label | | batchSize | number | 50 | Events per HTTP request | | flushInterval | number (ms) | 30000 | Auto-flush interval | | maxQueueSize | number | 10000 | Max queued events before oldest are dropped | | maxRetries | number | 3 | HTTP retry attempts on failure | | sessionTimeout | number (ms) | 1800000 | Idle timeout before a new session starts | | autoPageView | boolean | true | Track page_view on pushState / popstate | | autoError | boolean | true | Capture window.onerror and unhandled rejections |

API Reference

analytics.init(options)

Initialize the SDK. Must be called before any other method.

analytics.identify(userId: string)

Associate the current user identity with subsequent events.

analytics.track(eventName: string, properties?: Record<string, unknown>)

Queue a custom event. The event is sent in the next flush batch.

analytics.trackPageView(properties?: Record<string, unknown>)

Queue a page_view event enriched with url, path, title, and referrer.

analytics.flush(): Promise<void>

Drain the queue immediately. Useful before critical navigation or logout.

analytics.destroy()

Stop the flush timer, send any pending events via sendBeacon, and reset state.

Event Schema

Each event sent to the server includes:

| Field | Source | | ------------- | -------------------------------------- | | eventName | Argument to track | | timestamp | ISO-8601 string at enqueue time | | sessionId | Managed internally; rotates on timeout | | userId | Set by identify | | anonymousId | Persisted in localStorage | | platform | From options (default "web") | | appVersion | From options | | os | Inferred from navigator.userAgent | | page | window.location.pathname | | properties | Custom payload passed to track |

Automatic Events

When enabled, the SDK tracks the following events without extra code:

| Event | Trigger | Auto-enabled by | | ----------- | ------------------------------- | -------------------- | | page_view | pushState, popstate, init | autoPageView: true | | error | window.onerror | autoError: true | | error | unhandledrejection | autoError: true |

Building from Source

cd src/TraceX.Sdk.JavaScript
npm install
npm run build   # outputs to dist/
npm run test

Requirements

  • Modern browser with localStorage, fetch, and Web Crypto support for UUID generation through uuid
  • Node.js 20+ for building from source

License

MIT