Skip to content

MarcosPD3008/telemetry

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📊 Enhanced Telemetry Logging System

A production-ready telemetry library built with Angular and JSON Server, designed to provide comprehensive user behavior tracking, performance monitoring, and analytics capabilities.


🚀 Enhanced Features

Core Functionality

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

Advanced Features

🔧 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


🛠️ Enhanced Project Structure

/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

🚀 Getting Started

1️⃣ Install Dependencies

Run the following command from the root directory:

yarn install:all

This will install dependencies for both the Angular client and the JSON Server backend.


2️⃣ Start the Application

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:server

🔧 Enhanced Configuration

Environment Configuration

Modify 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
};

Advanced Configuration

// 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)
    }
  }
}

📊 Enhanced Telemetry Flow

1. Event Tracking

  • 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

2. Data Storage

  • 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

3. Intelligent Syncing

  • 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

4. Analytics Ready

  • Structured Data → Type-safe events with rich metadata
  • Export Capabilities → Easy to integrate with external analytics
  • Privacy Controls → Configurable data collection and retention

🎯 Usage Examples

Basic Tracking

// Automatic page tracking is enabled by default
// The service automatically tracks:
// - Page view time
// - Navigation events  
// - Performance metrics
// - Error events

User Action Tracking

// 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
});

Custom Events

// 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 });

Performance Monitoring

// Track custom performance metrics
this.telemetry.trackPerformance('api_response_time', 150, 'ms');
this.telemetry.trackPerformance('memory_usage', 50.5, 'MB');

Statistics & Health

// 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();

🛠️ Future Enhancements

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


📦 Library Export

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';

Package.json Configuration

{
  "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"
    }
  }
}

🔒 Privacy & Security

Data Minimization

  • Only collect necessary data with configurable retention
  • Anonymized user tracking options
  • Privacy-first design principles

Security Features

  • HTTPS-only communication
  • Data encryption in transit
  • Secure storage practices with IndexedDB

GDPR Compliance

  • 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.

About

A lightweight telemetry tracking system built with Angular

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors