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

sudo-query

v1.0.0

Published

A lightweight TypeScript analytics SDK for tracking events in browser and Node.js applications. Collect user behavior data with automatic batching, anonymous user tracking, and reliable delivery.

Readme

SudoQuery

A lightweight TypeScript analytics SDK for tracking events in browser and Node.js applications. Collect user behavior data with automatic batching, anonymous user tracking, and reliable delivery.

Features

  • Event Tracking - Track custom events with properties
  • Automatic Batching - Accumulate events locally to reduce network requests
  • Anonymous Users - Track unauthenticated users with persistent anonymous IDs
  • Super Properties - Attach default properties to all events
  • Auto-Flush - Automatically sends events on page unload using navigator.sendBeacon()
  • Periodic Auto-Flush - Configurable interval-based automatic event flushing
  • Cross-Platform - Works in both browsers and Node.js
  • TypeScript Support - Full type definitions included

Installation

npm install git+ssh://[email protected]/picaf/hyper-analytics-ts.git#release

Quick Start

import { SudoQuery } from 'sudo-query';

// Initialize the SDK
SudoQuery.init();

// Track an event
SudoQuery.track('button_click', {
  button_id: 'submit',
  page: '/checkout'
});

Usage

Initialization

Call init() once when your application loads. You can optionally configure:

import { SudoQuery } from 'sudo-query';

SudoQuery.init({
  flushInterval: 5000,    // Auto-flush every 5 seconds (optional)
  batchSize: 20,          // Batch 20 events before flushing (default: 10)
  endpoint: 'https://api.example.com/events',  // Custom endpoint (default: http://hyper-analytics-alb-c33157e-1810523293.ap-south-1.elb.amazonaws.com/push_batch)
  token: 'YOUR_PROJECT_TOKEN'  // Project token for authentication (required)
});

Important: Configuration can only be set during initialization and cannot be modified afterward.

This sets up:

  • A page visibility listener to automatically flush events when the user navigates away
  • A periodic flush timer (if flushInterval is provided)

Identifying Users

Set a user ID to associate events with authenticated users:

// Set user ID
SudoQuery.setUser('user_123');

// Get current user ID
const userId = SudoQuery.getUser();

// Clear user ID (on logout)
SudoQuery.removeUser();

Tracking Events

Track events with custom properties. Properties must be JSON serializable (primitives only - no nested objects):

SudoQuery.track('page_view', {
  page: '/home',
  referrer: 'https://google.com'
});

SudoQuery.track('purchase', {
  product_id: 'prod_456',
  price: 29.99,
  quantity: 2
});

Super Properties

Attach default properties to every event:

// Add super properties
SudoQuery.setSuperProperty('app_version', '1.0.0');
SudoQuery.setSuperProperty('environment', 'production');

// Get all super properties
const props = SudoQuery.getSuperProperties();

// Clear all super properties
SudoQuery.clearSuperProperties();

Manual Flush

Force upload of pending events:

await SudoQuery.flush();

Configuration Options

All configuration is done through the init() method:

| Option | Type | Default | Description | |--------|------|---------|-------------| | flushInterval | number \| undefined | undefined | Interval in milliseconds for periodic auto-flush. If not set, periodic flush is disabled. | | batchSize | number \| undefined | 10 | Number of events to accumulate before auto-flushing. | | endpoint | string \| undefined | "http://hyper-analytics-alb-c33157e-1810523293.ap-south-1.elb.amazonaws.com/push_batch" | URL where events are sent. | | token | string \| undefined | undefined | Project token for authentication. Required for sending events. |

Example Configurations

Default configuration:

SudoQuery.init();
// Uses: batchSize=10, endpoint="http://hyper-analytics-alb-c33157e-1810523293.ap-south-1.elb.amazonaws.com/push_batch", no periodic flush

High-frequency tracking:

SudoQuery.init({
  flushInterval: 2000,   // Flush every 2 seconds
  batchSize: 50,         // Larger batches
  endpoint: 'https://analytics-api.example.com/batch'
});

Low-latency mode:

SudoQuery.init({
  flushInterval: 1000,   // Flush every second
  batchSize: 5            // Small batches
});

API Reference

SudoQuery

All functionality is accessed through the SudoQuery class.

| Method | Description | |--------|-------------| | init(config?) | Initialize the SDK with optional configuration | | setUser(userId: string) | Set current user ID | | getUser(): string \| null | Get current user ID | | removeUser() | Clear user ID | | track(eventName: string, properties: JSONSerializable) | Track an event | | setSuperProperty(key: string, value: JSONSerializable) | Add a super property | | getSuperProperties(): Record<string, JSONSerializable> | Get all super properties | | clearSuperProperties() | Remove all super properties | | flush(useBeacon?: boolean): Promise<void> | Manually flush pending events | | get batchSize(): number | Get current batch size (read-only) | | get endpoint(): string | Get current endpoint URL (read-only) |

Types

type JSONSerializable =
  | string
  | number
  | boolean
  | null
  | JSONSerializable[]
  | { [key: string]: JSONSerializable };

Browser Support

The SDK uses localStorage for persisting anonymous IDs and navigator.sendBeacon() for reliable delivery during page unload. Works in all modern browsers.

License

ISC