Performance Metrics SDK is a lightweight, extensible JavaScript library for collecting and analyzing web performance metrics with minimal setup.
- 🚀 Automatic Performance Tracking
- 🔍 Custom Metric Measurement
- 🔌 Plugin System
- 🛡️ Error Tracking
- 📊 Configurable Metric Collection
- 🌐 Browser Compatibility Checks
npm install performantrics
import Performantrics from 'performantrics';
// Initialize with basic configuration
const tracker = new Performantrics({
projectId: 'my-project',
endpoint: 'https://metrics-collector.com/track',
debugMode: true
});
// Track custom performance measurement
tracker.startCustomMeasure('login-process');
// ... login logic
tracker.endCustomMeasure('login-process');
const tracker = new Performantrics({
projectId: 'my-project',
endpoint: 'https://metrics-collector.com/track',
debugMode: true,
sampleRate: 0.5, // Only track 50% of metrics
disabledMetrics: ['resource'], // Disable specific metric types
sensitiveDataFilter: (metric) => {
// Remove sensitive metadata
delete metric.metadata?.sensitiveInfo;
return metric;
}
});
Option | Type | Description | Default |
---|---|---|---|
projectId |
string |
Unique identifier for your project | undefined |
endpoint |
string |
Metrics collection endpoint | undefined |
debugMode |
boolean |
Enable console logging | false |
sampleRate |
number |
Percentage of metrics to collect | 1.0 |
disabledMetrics |
string[] |
Metrics types to ignore | [] |
sensitiveDataFilter |
Function |
Custom metric filtering | undefined |
startCustomMeasure(name: string, metadata?: object)
: Begin custom performance trackingendCustomMeasure(name: string, metadata?: object)
: End custom performance trackingrecordMetric(metric: object)
: Manually record a performance metricgetMetrics()
: Retrieve collected metricsclearMetrics()
: Clear all collected metricsuse(plugin: PerformancePlugin)
: Add a plugin to the SDK
The SDK checks for essential browser APIs:
PerformanceObserver
performance
fetch
Incompatible browsers will log warnings but won't break your application.
Automatically captures:
- Global
error
events - Unhandled Promise rejections
- Paint metrics
- Navigation metrics
- Resource loading
- Custom measurements
- Long tasks
- Fork the repository
- Create your feature branch
- Commit changes
- Push to the branch
- Create a Pull Request
Open an issue on GitHub for bug reports or feature requests.