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

video-buffer-tracker

v2.0.2

Published

Professional video buffering analytics & tracking library for monitoring video streaming performance, buffering progress, and user experience in real-time. Perfect for video platforms, e-learning apps, and media analytics.

Readme

🎬 Video Buffer Tracker

npm version npm downloads License: MIT TypeScript

Professional Video Buffering Analytics & Tracking Library - Monitor video buffering progress, track streaming performance, and analyze user viewing experience in real-time.

🚀 Features

  • Real-time Video Buffering Tracking - Monitor buffering progress as users watch videos
  • Advanced Analytics Integration - Send buffering data to your analytics platform
  • Performance Monitoring - Track video streaming performance and user experience
  • Memory Efficient - Optimized for production with minimal bundle size (32KB)
  • TypeScript Support - Full type safety and IntelliSense support
  • Modular Architecture - Clean, maintainable codebase with focused services
  • Cross-browser Compatible - Works with all modern browsers
  • Zero Dependencies - Lightweight with only tslib as peer dependency

📦 Installation

npm install video-buffer-tracker
yarn add video-buffer-tracker
pnpm add video-buffer-tracker

🎯 Quick Start

import { VideoBufferTracker } from "video-buffer-tracker";

// Create tracker instance
const tracker = new VideoBufferTracker({
  debug: true,
  onBufferData: (data) => {
    console.log("Buffering data:", data);
    // Send to your analytics service
    analytics.track("video_buffering", data);
  },
});

// Setup tracking for video element
const video = document.querySelector("video");
await tracker.setupVideoTracking(video, video.src);

// Get current buffering data
const bufferData = tracker.getBufferData();
console.log("Current buffer:", bufferData);

🔧 API Reference

VideoBufferTracker

The main class for video buffering tracking and analytics.

Constructor Options

interface VideoBufferTrackerConfig {
  /** Enable debug logging */
  debug?: boolean;

  /** Minimum time between progress updates (milliseconds) */
  progressThrottleMs?: number;

  /** Time remaining to trigger final probe (seconds) */
  finalProbeThreshold?: number;

  /** Epsilon for range merging (seconds) */
  rangeMergeEpsilon?: number;

  /** Legacy: URL to send analytics data */
  trafficEventUrl?: string;

  /** Callback function for buffer data */
  onBufferData?: (data: BufferData) => void | Promise<void>;
}

Methods

| Method | Description | | ------------------------------------- | ----------------------------------- | | setupVideoTracking(video, videoUrl) | Setup tracking for a video element | | getBufferData() | Get current buffer data | | getTrackingStats() | Get current tracking statistics | | destroy() | Stop tracking and cleanup resources | | isTrackingActive() | Check if tracking is active |

📊 Data Structure

BufferData

interface BufferData {
  file_size: number; // Total buffered bytes
  buffered_ranges: Array<{
    // Buffered time ranges
    start: number;
    end: number;
  }>;
  duration: number; // Video duration in seconds
  current_time: number; // Current playback time
  is_complete: boolean; // Whether video is fully buffered
}

🔧 Usage Examples

Basic Video Tracking

import { VideoBufferTracker } from "video-buffer-tracker";

const tracker = new VideoBufferTracker();
const video = document.querySelector("video");

await tracker.setupVideoTracking(video, video.src);

// Monitor buffering progress
setInterval(() => {
  const data = tracker.getBufferData();
  console.log(`Buffered: ${data.file_size} bytes`);
}, 1000);

Analytics Integration

const tracker = new VideoBufferTracker({
  onBufferData: (data) => {
    // Send to Google Analytics
    gtag("event", "video_buffering", {
      buffered_bytes: data.file_size,
      buffered_percent: (data.file_size / totalSize) * 100,
      video_duration: data.duration,
    });

    // Send to custom analytics
    fetch("/api/analytics/video", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify(data),
    });
  },
});

Performance Monitoring

const tracker = new VideoBufferTracker({
  debug: true,
  progressThrottleMs: 500,
  finalProbeThreshold: 0.5,
});

// Track performance metrics
tracker.onBufferData = (data) => {
  const stats = tracker.getTrackingStats();

  performance.mark("video-buffer-update");
  performance.measure(
    "buffer-calculation",
    "video-buffer-start",
    "video-buffer-update"
  );

  console.log("Performance:", performance.getEntriesByType("measure"));
};

Advanced Configuration

const tracker = new VideoBufferTracker({
  debug: false,
  progressThrottleMs: 250, // Update every 250ms
  finalProbeThreshold: 0.2, // Final check at 0.2s remaining
  rangeMergeEpsilon: 0.5, // Merge ranges within 0.5s
  trafficEventUrl: "https://api.example.com/analytics",
  onBufferData: (data) => {
    // Custom analytics logic
    if (data.is_complete) {
      console.log("Video fully buffered!");
    }
  },
});

🏗️ Architecture

The library uses a modular architecture with focused services:

  • VideoSizeService - Handles video file size detection with caching
  • BufferCalculationService - Manages buffer range calculations and merging
  • AnalyticsService - Handles analytics submission and callback execution
  • EventManager - Manages event listeners and cleanup
  • ValidationUtils - Input validation and error handling
  • Logger - Configurable logging system

🔍 Use Cases

Video Streaming Platforms

  • Monitor buffering performance across different video qualities
  • Track user experience and identify streaming issues
  • Optimize CDN delivery based on buffering patterns

E-learning Applications

  • Track video completion rates and engagement
  • Monitor student viewing behavior
  • Identify technical issues affecting learning

Media Analytics

  • Measure video performance metrics
  • Track user engagement patterns
  • Optimize content delivery

Performance Monitoring

  • Real-time video streaming analytics
  • User experience monitoring
  • Technical issue detection

🚀 Performance

  • Bundle Size: 32KB (minified and optimized)
  • Memory Usage: Minimal with proper cleanup
  • CPU Impact: Low with configurable throttling
  • Network: Efficient with caching and timeouts

🔧 Development

Building

npm run build

Development Mode

npm run dev

Testing

# Open test.html in browser
npm run test

📈 Migration from v1.x

The v2.0.0 release includes breaking changes for improved architecture:

// v1.x
const tracker = new VideoDownloadTracker({
  trafficEventUrl: "https://api.example.com/analytics",
});

// v2.0.0
const tracker = new VideoBufferTracker({
  onBufferData: (data) => {
    // Send to analytics
    fetch("https://api.example.com/analytics", {
      method: "POST",
      body: JSON.stringify(data),
    });
  },
});

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

📄 License

MIT License - see LICENSE file for details.

🔗 Related Packages

📞 Support


Made with ❤️ for the video streaming community