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

swing-sdk

v1.0.26

Published

A powerful session recording and user behavior analytics SDK built for simplicity and privacy.

Readme

Swing SDK

A powerful session recording and user behavior analytics SDK built for simplicity and privacy.

Features

  • 🎥 Session Recording - Full session replay with rrweb
  • 🔍 Automatic Event Tracking - Clicks, forms, navigation
  • 📝 Console Tracking - Capture console logs and errors
  • 👤 User Management - Identify and track users
  • 📊 Custom Events - Track business-specific events
  • 🔒 Privacy Controls - Simple CSS-based redaction
  • ⚛️ React Integration - Easy React hooks and provider

Quick Start

Installation

npm install @swing/sdk

Basic Usage

import { SwingProvider } from '@swing/sdk';

// Wrap your app
function App() {
  return (
    <SwingProvider apiKey="your-api-key">
      <YourApp />
    </SwingProvider>
  );
}

// Use in components
import { useSwingSDK } from '@swing/sdk';

function LoginComponent() {
  const { identifyUser, sendCustomEvent } = useSwingSDK();
  
  const handleLogin = (user) => {
    identifyUser(user.id, { email: user.email });
    sendCustomEvent('user_login', { method: 'email' });
  };
}

Privacy & Redaction

Simple CSS Selectors

// Initialize with redaction
<SwingProvider 
  apiKey="your-key"
  options={{
    redactFields: [
      'input[type="password"]',    // All password fields
      'input[type="email"]',       // All email fields  
      '.sensitive-data',           // Any element with this class
      '#credit-card-number',       // Specific element ID
      '[data-private]'             // Any element with data-private attribute
    ]
  }}
>
  <App />
</SwingProvider>

// Update redaction dynamically
const { setRedactedFields, getRedactedFields } = useSwingSDK();

// Add more fields to redact
setRedactedFields([
  ...getRedactedFields(),
  '.payment-info',
  '#social-security'
]);

HTML Examples

<!-- These will be redacted -->
<input type="password" name="password" />
<input type="email" class="sensitive-data" />
<div data-private>Secret content</div>
<span class="credit-card">4111 1111 1111 1111</span>

<!-- These will be recorded normally -->
<input type="text" name="username" />
<button>Submit</button>
<div>Public content</div>

API Reference

SwingProvider Props

interface SwingSDKProviderProps {
  apiKey: string;                    // Your Swing API key
  children: ReactNode;
  options?: {
    userId?: string;                 // Initial user ID
    sessionId?: string;              // Custom session ID
    redactFields?: string[];         // CSS selectors to redact
  };
}

useSwingSDK Hook

const {
  // User Management
  setUser,              // (user: SwingUser) => void
  identifyUser,         // (userId: string, properties?) => void  
  clearUser,            // () => void
  
  // Custom Events
  sendCustomEvent,      // (name: string, properties?) => void
  
  // Privacy Controls
  setRedactedFields,    // (selectors: string[]) => void
  getRedactedFields,    // () => string[]
  
  // Status
  isInitialized         // boolean
} = useSwingSDK();

Advanced Usage

Custom Events

const { sendCustomEvent } = useSwingSDK();

// Track business events
sendCustomEvent('purchase_completed', {
  amount: 99.99,
  currency: 'USD',
  items: ['product_1', 'product_2']
});

// Track feature usage
sendCustomEvent('feature_used', {
  feature: 'dark_mode',
  enabled: true
});

User Management

const { identifyUser, setUser, clearUser } = useSwingSDK();

// Simple identification
identifyUser('user_123');

// With properties
identifyUser('user_123', {
  email: '[email protected]',
  plan: 'premium',
  signupDate: '2024-01-15'
});

// Full user object
setUser({
  id: 'user_123',
  email: '[email protected]',
  name: 'John Doe',
  properties: {
    plan: 'premium',
    lastSeen: new Date()
  }
});

// Clear user (logout)
clearUser();

Privacy Controls

const { setRedactedFields, getRedactedFields } = useSwingSDK();

// Get current redacted fields
const current = getRedactedFields();
console.log(current); // ['input[type="password"]']

// Add more fields
setRedactedFields([
  ...current,
  '.sensitive',
  '#secret-div',
  'input[name="ssn"]'
]);

// Replace all fields
setRedactedFields([
  'input[type="password"]',
  'input[type="email"]',
  '.payment-form input'
]);

What Gets Tracked Automatically

🖱️ Click Events

  • Button clicks
  • Link clicks
  • Any element clicks
  • Element details (tag, id, class, text)

📝 Form Events

  • Form submissions
  • Field data (respecting redaction)
  • Form metadata (action, method)

🧭 Navigation Events

  • Page changes (SPA)
  • Route transitions
  • URL changes

📊 Console Events

  • console.log(), console.error(), console.warn(), console.info()
  • JavaScript errors and stack traces
  • Unhandled promise rejections

🎥 Session Recording

  • DOM changes
  • Mouse movements
  • Scroll events
  • Input interactions (with privacy controls)

Privacy & Compliance

Default Privacy

  • Passwords masked by default
  • Simple CSS-based redaction
  • No complex configuration needed

GDPR/CCPA Ready

// Redact PII fields
setRedactedFields([
  'input[type="email"]',
  'input[name*="name"]',
  'input[name*="phone"]',
  '.pii-data',
  '[data-sensitive]'
]);

Production Best Practices

<SwingProvider 
  apiKey={process.env.SWING_API_KEY}
  options={{
    redactFields: [
      // Always redact these in production
      'input[type="password"]',
      'input[type="email"]',
      '.payment-info',
      '.personal-data',
      '[data-private]'
    ]
  }}
>

Backend Integration

The SDK sends data to your Swing backend at /upload. See the Backend Documentation for setup instructions.

Examples

Check out the Fitia demo app for complete examples of:

  • User login/logout tracking
  • Form submission tracking
  • Custom business events
  • Privacy redaction
  • Session replay

Support