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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rum-client

v0.1.3

Published

Real User Monitoring SDK - TypeScript client library with API key validation

Readme

JSClient SDK

Real User Monitoring SDK - TypeScript client library with API key validation

Installation

npm install RUM-CLIENT

RUM SDK — JSClient-SDK

A lightweight Real User Monitoring (RUM) client library (TypeScript). This README summarizes the features implemented so far, integration examples, build notes, and suggested next steps.

What this repo contains

  • Source: index.ts
  • Implemented SDK features:
    • API Key Validation: validates the provided apiKey against the backend /api/validate-key during SDK construction.
    • Device ID: generates and persists deviceId in localStorage (rum_device_id).
    • User & Session IDs: userId persisted in localStorage (rum_user_id); sessionId persisted for the browser session (sessionStorage rum_session_id).
    • Tracking Methods: getDeviceId(), trackPageView(), trackEvent(), trackError() — safe to call after onReady.
    • Send to Backend: posts events to /v1/track using navigator.sendBeacon when possible, falling back to fetch.
    • Batching & Periodic Flush: in-memory queue with configurable batch size (default 5) and periodic flush (default 5s).
    • Offline Queue (localStorage fallback): failed batches are saved to localStorage under rum_offline_queue and retried on init or via processOfflineQueue().

Key file

  • index.ts — main SDK implementation (TypeScript). See the RUM class for public API and configuration.

Usage — React (recommended)

  • Initialize once (root of app) and use onReady before calling tracking methods because validation is asynchronous.

Example (React + TypeScript):

import React, { useEffect, useRef } from 'react';
import RUM from './dist/index.js'; // or from your built package

export default function App() {
  const rumRef = useRef<RUM | null>(null);

  useEffect(() => {
    rumRef.current = new RUM({
      apiKey: 'REPLACE_WITH_YOUR_KEY',
      onReady: () => {
        console.log('RUM ready', rumRef.current?.getDeviceId());
        rumRef.current?.trackPageView();
      },
      onError: (err) => console.error('RUM error', err)
    });
  }, []);

  return <div>App content</div>;
}

Usage — Plain JS (script tag)

  • If you build a UMD bundle or attach RUM to window, use:
<script src="/path/to/rum.bundle.js"></script>
<script>
  const rum = new window.RUM({
    apiKey: 'REPLACE_WITH_YOUR_KEY',
    onReady() {
      console.log('deviceId', rum.getDeviceId());
      rum.trackPageView();
    },
    onError(err) { console.error(err); }
  });
</script>

Build / bundling (quick)

  • The package is TypeScript source (index.ts). Minimal compile with tsc:
# install TypeScript locally if needed
npm install --save-dev typescript

# compile single file to `dist` (adjust `tsc` options as needed)
npx tsc index.ts --outDir dist --module ES2020 --target ES2017
  • Or add a build script to package.json:
"scripts": {
  "build": "tsc"
}

and run npm run build.

Behaviour & notes

  • The constructor validates the apiKey asynchronously; prefer onReady before tracking.
  • All outgoing payloads include apiKey, deviceId, userId, and sessionId where applicable.
  • The SDK queues events and sends batched payloads to /v1/track — failed batches are saved to the offline queue.
  • Offline queue uses localStorage as the current fallback; consider IndexedDB for production reliability.

Next suggested improvements (I can implement)

  • IndexedDB offline queue for larger/more reliable storage.
  • Exponential backoff and retry for failed sends.
  • Public flush() to force immediate send of queued events.
  • Configurable batchSize, flushIntervalMs, and offline storage selection.
  • Implement additional tracking features from the full reference (performance, network, session replay, breadcrumbs).

If you want, I can implement one of the improvements above (IndexedDB, retry/backoff, or a demo app). Tell me which and I'll proceed.