analyzer-analytics
v0.1.3
Published
Lightweight analytics tracker for web applications (<3KB gzipped)
Downloads
409
Maintainers
Readme
analyzer-analytics
Lightweight analytics tracker for web applications. Under 3KB gzipped with support for older browsers and optimized for slow networks.
Features
- Tiny footprint - Core bundle <3KB gzipped
- Auto pageview tracking - Tracks pageviews on load
- Custom events - Track any event with properties
- Offline support - Events queued and sent when online
- sendBeacon - Reliable delivery on page unload
- Bot filtering - Automatically ignores known bots
Quick Start
Script Tag
<script
src="/analytics.min.js"
data-api-key="your_api_key"
></script>Track Events
// Custom events
analytics.track('signup', { plan: 'pro' });
analytics.track('purchase', { product_id: 'abc', price: 99 });Installation
Option 1: Script Tag (recommended)
<script
src="/path/to/analytics.min.js"
data-api-key="pk_test_abc123"
data-debug="true"
></script>To override the endpoint (e.g., for local development):
<script
src="/path/to/analytics.min.js"
data-api-key="pk_test_abc123"
data-endpoint="http://localhost:8080"
data-debug="true"
></script>Option 2: ES Module
import analytics from 'analyzer-analytics';
// Default endpoint is production (https://analyzer-ancient-field-3067.fly.dev)
analytics.init('pk_test_abc123');
// Or override for local development:
analytics.init('pk_test_abc123', {
endpoint: 'http://localhost:8080'
});Configuration
| Attribute | Default | Description |
|-----------|---------|-------------|
| data-api-key | required | Your project API key |
| data-endpoint | https://analyzer-ancient-field-3067.fly.dev | Analytics server URL (optional override) |
| data-debug | false | Enable console logging |
| data-auto-track | true | Auto-track pageviews |
API
// Initialize
analytics.init(apiKey, { endpoint, debug, autoTrack });
// Track event
analytics.track('event_name', { key: 'value' });
// Force send queued events
await analytics.flush();
// Get visitor/session IDs
analytics.instance.getVisitorId();
analytics.instance.getSessionId();Documentation
See the complete SDK Usage Guide for:
- Framework integration (Astro, React, Vue, Next.js)
- SPA route tracking
- Event tracking examples
- Troubleshooting
Development
Prerequisites
- Bun v1.0 or later
Setup
bun installBuild
# Build all formats
bun run build
# Development mode (watch)
bun run devBuild Output
| File | Size | Description |
|------|------|-------------|
| dist/analytics.min.js | ~1.6KB gzip | Core build (recommended) |
| dist/analytics.esm.js | ~10KB gzip | ES Module |
| dist/analytics.js | ~10KB gzip | IIFE unminified |
| dist/analytics.full.min.js | ~8KB gzip | Full features |
Testing
bun test
bun test:watchSize Check
bun run size-checkTarget: Core bundle <3KB gzipped
License
MIT
