A production-ready, full-stack web analytics platform featuring real-time session tracking, interactive heatmaps, funnel analysis, and session replay capabilities.
Analytics OS is a comprehensive, self-hosted analytics platform designed to provide deep insights into user behavior without compromising data privacy or requiring third-party services. Built with modern web technologies, it combines lightweight client-side tracking with a robust backend infrastructure and an intuitive visualization dashboard.
- Session Management: Automatic visitor identification and session lifecycle tracking
- Event Capture: Page views, clicks, scrolls, form interactions, and custom events
- Behavioral Signals: Rage clicks, dead clicks, quickback detection, excessive scrolling
- Error Monitoring: JavaScript errors and unhandled promise rejections
- Geographic Data: Country, region, and city-level tracking via IP geolocation
- UTM Campaign Tracking: Source, medium, and campaign attribution
- Device Detection: Browser, OS, and device type classification
- Bot Filtering: Intelligent bot detection to ensure data quality
- Overview Analytics: Real-time metrics with 7-day trend charts
- Session Explorer: Detailed user journey analysis with timeline views
- Interactive Heatmaps:
- Click density visualization with thermal gradients
- Element-level engagement overlays (Area Maps)
- Scroll attention mapping with viewport fold markers
- Funnel Analysis: Multi-step conversion tracking with drop-off visualization
- Session Replay: rrweb-powered DOM recording and playback
- Event Timeline: Filterable event stream with search capabilities
- Conversion Attribution: Filter heatmaps by converted users
- Goal Configuration: Path-based or event-based conversion goals
- Frustration Detection: Identify user pain points with rage/dead click analysis
- Geographic Distribution: World map visualization with country-level metrics
- Device & Browser Analytics: Platform distribution insights
- UTM Performance: Campaign effectiveness tracking
- Real-time Monitoring: Live session tracking with WebSocket updates
- GDPR Compliant: Consent management and DNT (Do Not Track) respect
- Data Masking: Automatic PII protection for sensitive inputs
- Self-Hosted: Complete data ownership and control
- Secure Authentication: Password-protected dashboard access
- API Key Protection: Optional authentication for event ingestion
Frontend:
- React 19 with TypeScript
- Vite for blazing-fast builds
- React Router for routing
- SWR for data fetching and caching
- Recharts for data visualization
- Socket.IO client for real-time updates
- Tailwind CSS for styling
Backend:
- Node.js with Express
- TypeScript for type safety
- MongoDB with Mongoose ODM
- Zod for runtime validation
- Socket.IO for WebSocket communication
- Layered architecture (Controller → Service → Repository → Model)
Tracking:
- Vanilla JavaScript (zero dependencies)
- IIFE pattern for global scope isolation
- Batch processing with configurable flush intervals
- Resilient retry logic with exponential backoff
- rrweb for session recording
Backend Flow:
Controllers (HTTP boundary)
↓
Services or repositories (business rules/data access)
↓
Repositories (Data access)
↓
Models (MongoDB schemas)
Separation of Concerns:
- API validation via middleware (Zod schemas)
- Authentication/authorization as middleware
- Error handling with global error middleware
- Type safety enforced throughout the stack
Performance Optimizations:
- Event batching reduces network overhead
- MongoDB indexes for fast queries
- Canvas-based heatmap rendering
- Efficient aggregation pipelines
- Client-side data caching with SWR
- Node.js v20 or higher
- MongoDB 7.0+ running locally or via Docker
- npm or yarn package manager
- Clone the repository:
git clone https://github.com/yourusername/analytics-app.git
cd analytics-app- Install all dependencies:
npm run install:all- Configure environment variables:
Create backend/.env:
PORT=4000
MONGODB_URI=mongodb://localhost:27017/analytics_db
NODE_ENV=development
ADMIN_PASSWORD=your-secure-password
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:5173,http://localhost:3001
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=1000- Start MongoDB (if not already running):
# Using Docker
docker run -d -p 27017:27017 --name mongodb mongo:latest
# Or using installed MongoDB
mongod --dbpath /path/to/data/directory- Start the full stack:
npm run devThis starts:
- Backend API on
http://localhost:4000 - Frontend Dashboard on
http://localhost:5173 - Demo Site on
http://localhost:3001
Seed Sample Data (for immediate testing):
curl -X POST \
-H "Authorization: Bearer your-secure-password" \
http://localhost:4000/api/seedThis creates 15 sample sessions with realistic user journeys, clicks, and scroll data.
Option A: Use the Demo Site (Instant)
- Navigate to
http://localhost:3001/ - Click buttons, scroll pages, navigate between sections
- Interactions are automatically tracked and batched
- Events flush every 5 seconds or on page unload
Option B: Use Seed Data (Pre-populated)
curl -X POST \
-H "Authorization: Bearer your-secure-password" \
http://localhost:4000/api/seedOpen http://localhost:5173/ and log in with your ADMIN_PASSWORD.
The landing page shows aggregate metrics:
Key Metrics (Top Cards):
- Total Sessions: All tracked sessions
- Total Events: All captured interactions
- Avg Session Duration: Mean time spent per session
- Bounce Rate: % of single-page sessions
7-Day Trend Charts:
- Sessions over time (line chart)
- Events distribution by type (bar chart)
- Geographic distribution (world map)
- Top pages by traffic (table)
Device & Platform Analytics:
- Browser distribution (pie chart)
- Device type breakdown (desktop/mobile/tablet)
UTM Campaign Performance:
- Traffic sources ranked by session count
Detailed session explorer with filterable table:
Columns:
- Session ID (clickable for details)
- Device type & country flag
- Duration & event count
- Frustration signals (rage clicks, dead clicks)
- First seen timestamp
- Bounce indicator
Filters:
- Date range picker
- Device type (desktop/mobile/tablet)
- Country selector
- Bounce status
Session Detail View:
- Complete event timeline
- Session metadata (user agent, location, UTM params)
- Frustration signals highlighted
- Session replay player (if recording available)
Interactive visualization of user interactions:
1. Click Heatmap Mode:
- Thermal density visualization
- Red (high density, 3+ clicks)
- Yellow (medium, 2 clicks)
- Blue (low, 1 click)
- Hover to see click counts and selectors
2. Area Maps Mode:
- Element-level engagement overlays
- Colored boxes on clickable elements
- Percentage distribution labels
- Aggregated by CSS selector
3. Scroll Attention Mode:
- Linear gradient showing viewport time
- Color intensity = engagement level
- Fold markers at 25%, 50%, 75%
- Identifies high-attention content areas
Controls:
- Target Path: Select which page to analyze
- User Session: Filter to specific session (or all)
- Goal Filters: Show only converted users
- Path-based (e.g.,
/successpage) - Event-based (e.g.,
subscribeevent)
- Path-based (e.g.,
How to Use:
- Select a URL from the dropdown
- Choose heatmap mode (Click/Area/Scroll)
- Toggle filters as needed
- Hover over points for details
Multi-step conversion analysis:
Creating a Funnel:
- Click "Create Funnel"
- Add funnel steps (pages or events):
- Step 1: Landing page (
/) - Step 2: Pricing page (
/pricing) - Step 3: Checkout (
/checkout) - Step 4: Success (
/success)
- Step 1: Landing page (
- Click "Analyze"
Funnel Visualization:
- Step-by-step conversion rates
- Drop-off percentages between steps
- Total conversions vs. total entries
- Visual funnel chart with width proportional to users
Insights:
- Identify bottleneck steps
- Optimize high-drop-off pages
- Track conversion improvements over time
Test various tracking scenarios:
Available Tests:
- Click tracking on buttons
- Custom event firing
- Error simulation
- Form interaction tracking
- Navigation testing (SPA detection)
Real-Time Validation:
- Open browser DevTools → Network tab
- See batched POST requests to
/api/events - Verify event structure and timing
Dashboard Endpoints:
- Protected by Bearer token authentication
- Header:
Authorization: Bearer YOUR_ADMIN_PASSWORD
Event Ingestion:
- Public endpoint (no auth required by default)
- Optional API key protection via
REQUIRE_API_KEYenv var
Ingest batched tracking events.
Request Body:
[
{
"projectId": "demo_project_001",
"visitorId": "visitor_123",
"sessionId": "session_456",
"timestamp": "2026-06-24T12:00:00.000Z",
"type": "click",
"url": "http://localhost:3001/",
"userAgent": "Mozilla/5.0...",
"data": {
"x": 220,
"y": 410,
"selector": "button#hero-cta",
"text": "Get Started"
}
}
]Response:
{
"success": true,
"message": "5 events ingested successfully"
}Retrieve all sessions with pagination.
Query Parameters:
limit(number): Results per page (default: 50)page(number): Page number (default: 1)
Response:
{
"success": true,
"data": [
{
"sessionId": "sess_01",
"visitorId": "vis_001",
"firstSeen": "2026-06-24T10:00:00.000Z",
"lastSeen": "2026-06-24T10:05:00.000Z",
"sessionDuration": 300,
"eventCount": 12,
"pageViewsCount": 4,
"bounce": false,
"deviceType": "desktop",
"country": "United States",
"utmSource": "google"
}
]
}Get event timeline for a specific session.
Response:
{
"success": true,
"data": [
{
"type": "page_view",
"timestamp": "2026-06-24T10:00:00.000Z",
"url": "http://localhost:3001/",
"data": { "title": "Home" }
},
{
"type": "click",
"timestamp": "2026-06-24T10:00:15.000Z",
"data": {
"selector": "button#cta",
"x": 220,
"y": 410
}
}
]
}Get heatmap data for a URL.
Query Parameters:
url(string, required): Target URLtype(string):clickorattention(default:click)sessionId(string, optional): Filter to specific sessionconvertedOnly(boolean): Show only converted usersconversionPath(string): Goal path (e.g.,/success)conversionEvent(string): Goal event (e.g.,subscribe)
Response (Click):
{
"success": true,
"url": "http://localhost:3001/",
"type": "click",
"data": [
{
"x": 220,
"y": 410,
"selector": "button#hero-cta",
"count": 5
}
]
}Response (Attention):
{
"success": true,
"url": "http://localhost:3001/",
"type": "attention",
"data": {
"0": 64,
"1": 48,
"2": 42
}
}List all tracked URLs.
Response:
{
"success": true,
"data": [
"http://localhost:3001/",
"http://localhost:3001/pricing",
"http://localhost:3001/checkout"
]
}List all saved funnels.
Response:
{
"success": true,
"data": [
{
"_id": "funnel_123",
"name": "Checkout Flow",
"steps": [
{ "type": "page_view", "value": "/" },
{ "type": "page_view", "value": "/pricing" },
{ "type": "page_view", "value": "/checkout" },
{ "type": "page_view", "value": "/success" }
]
}
]
}Seed database with sample data (development only).
Response:
{
"success": true,
"message": "Database seeded with 15 sessions",
"counts": {
"sessions": 15,
"events": 66,
"recordings": 5
}
}Clear all data from database (development only).
Response:
{
"success": true,
"message": "Database cleared successfully"
}# Backend unit tests (32 tests)
cd backend
npm test
# Frontend E2E tests (Playwright)
cd tests/e2e
npx playwright test
# With UI mode
npx playwright test --uiBackend:
- Event API validation
- Bot detection logic
- Enterprise feature guards
- Heatmap aggregation
- Session management
Frontend E2E:
- Tracker script injection
- Event batching and flushing
- Network failure resilience
- localStorage security errors
Build and run with Docker Compose:
docker-compose up -dThis starts:
- MongoDB (port 27017)
- Backend API (port 4000)
- Frontend (port 80)
Environment Configuration:
Update docker-compose.yml with production values:
environment:
- NODE_ENV=production
- MONGODB_URI=mongodb://mongodb:27017/analytics_db
- ADMIN_PASSWORD=${ADMIN_PASSWORD}
- ALLOWED_ORIGINS=https://yourdomain.com-
Security:
- Set strong
ADMIN_PASSWORD - Enable
REQUIRE_API_KEYfor event ingestion - Use HTTPS in production
- Configure proper CORS origins
- Set strong
-
Performance:
- MongoDB indexes are auto-created
- Consider read replicas for high traffic
- Use CDN for tracker script
-
Monitoring:
- Enable application logging
- Set up health check monitoring (
/healthendpoint) - Monitor MongoDB performance
-
Backup:
- Regular MongoDB backups
- Export analytics data via API
Contributions are welcome! Please follow these guidelines:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
Development Guidelines:
- Follow existing code style
- Add tests for new features
- Update documentation
- Ensure all tests pass
This project is licensed under the MIT License. See LICENSE for details.
- rrweb for session recording
- Recharts for visualization
- Phosphor Icons for UI icons
- Tailwind CSS for styling
- Issues: GitHub Issues
- Documentation: See SPEC.md for architecture details
- Heatmap Guide: See HEATMAP_FIXES.md for troubleshooting
Built with ❤️ for developers who value data ownership and privacy.