A production-ready telemetry library built with Angular and JSON Server, designed to provide comprehensive user behavior tracking, performance monitoring, and analytics capabilities.
✅ Page View Tracking - Automatic time spent tracking with session management
✅ User Action Tracking - Click, form, and interaction events with rich metadata
✅ Error Tracking - Automatic error capture and reporting with context
✅ Performance Monitoring - Page load times, memory usage, network metrics
✅ Custom Events - Flexible custom event tracking with immediate sync options
✅ Offline Support - IndexedDB storage with intelligent sync when online
✅ Network Intelligence - Smart syncing based on connection quality
✅ Retry Logic - Automatic retry with exponential backoff
✅ Session Management - Session-based event grouping
✅ Privacy Controls - Configurable data collection and retention
🔧 Library Architecture - Modular, extensible design for easy packaging
📦 Export Ready - Easy to package as standalone library
🎯 Type Safety - Full TypeScript support with proper interfaces
🔄 Event Handlers - Custom event callbacks for all major operations
📊 Statistics API - Real-time telemetry statistics and health monitoring
🛠️ Utility Functions - Browser info, performance metrics, data formatting
🎨 Configurable - Flexible configuration options with environment support
/TELEMETRY
│── /client # Angular frontend with enhanced telemetry
│ ├── src/app/services/
│ │ ├── telemetry.service.ts # Main orchestration service
│ │ ├── telemetry-storage.service.ts # IndexedDB management
│ │ ├── telemetry-sync.service.ts # Server communication
│ │ ├── telemetry-utils.service.ts # Utility functions
│ │ ├── telemetry.module.ts # Module configuration
│ │ └── telemetry-public-api.ts # Library exports
│ ├── src/app/models/
│ │ ├── log.model.ts # Basic log interface
│ │ ├── telemetry-config.model.ts # Configuration interface
│ │ └── telemetry-event.model.ts # Event type definitions
│ └── ...
│
│── /server # JSON Server backend
│ ├── db.json # Stores telemetry logs and events
│ ├── package.json # Server dependencies
│ └── ...
│
│── package.json # Root file for managing client & server together
│── README.md # Project documentation
Run the following command from the root directory:
yarn install:allThis will install dependencies for both the Angular client and the JSON Server backend.
To run both the client and server simultaneously, use:
yarn start:all- 🌍 Client: Runs at
http://localhost:4200/ - 🖥️ Server: Runs at
http://localhost:3000/
Alternatively, you can start them separately:
# Start Angular frontend
yarn start:client
# Start JSON Server backend
yarn start:serverModify environment.ts to configure telemetry settings:
export const environment = {
production: false,
apiBaseUrl: 'http://localhost:3000/telemetry',
telemetryEnabled: true,
syncInterval: 60000, // Sync logs every 60 seconds
debug: true
};// App configuration with event handlers
{
provide: TELEMETRY_CONFIG,
useValue: {
enabled: true,
apiBaseUrl: 'http://localhost:3000/telemetry',
syncInterval: 60000,
debug: true,
maxLocalLogs: 1000,
eventHandlers: {
onLogCreated: (event) => console.log('Event created:', event),
onSyncCompleted: (count) => console.log(`Synced ${count} events`),
onError: (error) => console.error('Telemetry error:', error)
}
}
}- User visits a page → Time is recorded in IndexedDB
- User interactions → Actions tracked with rich metadata
- Performance metrics → Automatic collection of load times, memory usage
- Error events → Automatic error capture with stack traces
- Local Storage → Events stored in IndexedDB with separate stores for logs and events
- Session Management → Events grouped by session for better analytics
- Metadata Enrichment → Browser info, network status, performance metrics
- Network Awareness → Only sync when connection is suitable
- Retry Logic → Automatic retry with exponential backoff
- Bulk Operations → Optimized for performance with batch processing
- Health Monitoring → Real-time statistics and quota management
- Structured Data → Type-safe events with rich metadata
- Export Capabilities → Easy to integrate with external analytics
- Privacy Controls → Configurable data collection and retention
// Automatic page tracking is enabled by default
// The service automatically tracks:
// - Page view time
// - Navigation events
// - Performance metrics
// - Error events// Track button clicks
this.telemetry.trackUserAction('button', 'click', 'submit-form');
// Track form interactions
this.telemetry.trackUserAction('input', 'focus', 'email-field');
// Track with custom metadata
this.telemetry.trackUserAction('button', 'click', 'purchase', {
productId: '123',
price: 29.99
});// Track business events
this.telemetry.trackCustom('purchase_completed', {
productId: '123',
amount: 29.99,
currency: 'USD'
});
// Track with immediate sync
this.telemetry.trackCustom('critical_event', {
type: 'security_alert'
}, { syncImmediate: true });// Track custom performance metrics
this.telemetry.trackPerformance('api_response_time', 150, 'ms');
this.telemetry.trackPerformance('memory_usage', 50.5, 'MB');// Get telemetry statistics
const stats = await this.telemetry.getStats();
console.log('Pending logs:', stats.logsCount);
console.log('Pending events:', stats.eventsCount);
console.log('Database size:', stats.databaseSize);
// Force sync all pending data
await this.telemetry.forceSync();✅ Advanced Analytics - Real-time dashboards and visualizations
✅ Machine Learning - Predictive analytics and anomaly detection
✅ A/B Testing - Built-in experimentation framework
✅ Real-time Streaming - WebSocket support for live data
✅ Multi-tenant Support - Organization and project management
✅ API Rate Limiting - Intelligent throttling and queuing
✅ Data Export - CSV, JSON, and analytics platform integrations
✅ Advanced Privacy - GDPR compliance tools and data anonymization
The enhanced telemetry system is designed to be easily packaged as a standalone library:
// Export all functionality
export * from './telemetry-public-api';
// Or export specific modules
export { TelemetryService } from './telemetry.service';
export { TelemetryModule } from './telemetry.module';{
"name": "@your-org/telemetry-library",
"version": "1.0.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts"
}
}
}- Only collect necessary data with configurable retention
- Anonymized user tracking options
- Privacy-first design principles
- HTTPS-only communication
- Data encryption in transit
- Secure storage practices with IndexedDB
- User consent management
- Data deletion capabilities
- Privacy controls and transparency
This enhanced telemetry system provides a production-ready foundation for comprehensive user behavior tracking, performance monitoring, and analytics capabilities while maintaining the flexibility to be used as a standalone library or integrated into existing applications.