Admin Analytics
The Admin Analytics module provides comprehensive business intelligence and administrative reporting capabilities for the DashClicks platform. This module is divided into specialized submodules for better organization and focused analytics functionality.
📊 Analytics Submodules
Platform Analytics
- Platform Metrics - Account growth, user analytics, and subscriber metrics
- Revenue Analytics - MRR, total revenue, churn, and lifetime value metrics
- Subscription Analytics - Active subscriptions, new subscriptions, and churn analysis
- Payment Analytics - Payment processing, fee collection, and account metrics
🏗️ Architecture Overview
- Location:
internal/api/v1/admin/routes/analytic.route.js - Service:
internal/api/v1/admin/services/analytic.service.js - Controller:
internal/api/v1/admin/controllers/analytic.controller.js - Route Prefix:
/v1/admin/analytics - Authorization: DashClicks staff only with administrative access
📈 Key Features
Comprehensive Analytics Coverage
- Platform Growth: Account and user growth tracking with growth rate calculations
- Revenue Intelligence: MRR, total revenue, churn analysis, and lifetime value metrics
- Subscription Management: Active subscription tracking, new subscriber analytics, and churn rates
- Payment Processing: Transaction analytics, fee collection, and payment account metrics
Advanced Data Processing
- Date Range Filtering: Customizable date range analysis with start_date and end_date parameters
- Growth Rate Calculations: Automated period-over-period growth rate calculations
- Time Series Data: Historical data analysis with trend identification
- Comparative Analytics: Current vs previous period comparisons
Administrative Features
- Staff Authorization: Restricted access to authorized DashClicks staff members
- Real-time Data: Live analytics data with current metrics
- Export Capabilities: Analytics data export for reporting and analysis
- Dashboard Integration: Integration with administrative dashboards
🔧 Technical Implementation
Data Processing Architecture
// Standard analytics query pattern
const { sDate, eDate, previousEndDate, previousStartDate } = getDateValues({ startDate, endDate });
// Growth rate calculation formula: ((present - past) / past) * 100
const growthRate = ((currentValue - previousValue) / previousValue) * 100;
MongoDB Aggregation Framework
- Complex Aggregations: Multi-stage aggregation pipelines for comprehensive analytics
- Collection Joins: Lookups across accounts, subscriptions, invoices, and user collections
- Data Transformation: Advanced data processing and metric calculations
- Performance Optimization: Optimized queries for large-scale data processing
Authentication & Authorization
- Admin Check:
adminAppCheck('analytics')middleware for route protection - Staff Validation: DashClicks staff member verification
- Rate Limiting:
validateLimitmiddleware for API rate limiting - Audit Logging: Comprehensive logging of all analytics access
🚀 Analytics Workflow
graph TD
A[Admin Request] --> B[Staff Authorization Check]
B --> C[Date Range Processing]
C --> D[Data Aggregation]
D --> E[Growth Rate Calculation]
E --> F[Response Formatting]
F --> G[Analytics Response]
D --> H[Current Period Data]
D --> I[Previous Period Data]
H --> E
I --> E
subgraph "Data Sources"
J[Accounts Collection]
K[Users Collection]
L[Subscriptions Collection]
M[Invoices Collection]
end
D --> J
D --> K
D --> L
D --> M
📁 Module Structure
analytics/
├── platform-analytics.md # Account and user growth metrics
├── revenue-analytics.md # MRR, revenue, and churn analytics
├── subscription-analytics.md # Subscription lifecycle analytics
└── payment-analytics.md # Payment processing analytics
🔗 API Endpoint Overview
Platform Analytics Endpoints
GET /v1/admin/analytics/platform/accounts- Account growth analyticsGET /v1/admin/analytics/platform/users- User growth analyticsGET /v1/admin/analytics/platform/new-subscribers- New subscriber metricsGET /v1/admin/analytics/platform/total-active-paying-accounts- Active paying accountsGET /v1/admin/analytics/platform/accounts-churn- Account churn analytics
Revenue Analytics Endpoints
GET /v1/admin/analytics/revenue/total-revenue- Total revenue analyticsGET /v1/admin/analytics/revenue/mrr- Monthly Recurring RevenueGET /v1/admin/analytics/revenue/mrr-pending- Pending MRR analyticsGET /v1/admin/analytics/revenue/mrr-added- Added MRR analyticsGET /v1/admin/analytics/revenue/other-revenue- Other revenue analyticsGET /v1/admin/analytics/revenue/revenue-churn- Revenue churn analyticsGET /v1/admin/analytics/revenue/avg-revenue-account- Average revenue per accountGET /v1/admin/analytics/revenue/avg-lifetime-revenue- Average lifetime revenue
Subscription Analytics Endpoints
GET /v1/admin/analytics/subscription/active-subscriptions- Active subscriptionsGET /v1/admin/analytics/subscription/new-subscriptions- New subscriptionsGET /v1/admin/analytics/subscription/subscription-churn- Subscription churn
Payment Analytics Endpoints
GET /v1/admin/analytics/payments/payment-accounts- Payment account analyticsGET /v1/admin/analytics/payments/active-payment-accounts- Active payment accountsGET /v1/admin/analytics/payments/payment-processed- Processed paymentsGET /v1/admin/analytics/payments/collected-fees- Collected fees analytics
🛡️ Security & Access Control
Administrative Authorization
- DashClicks Staff Only: All analytics endpoints restricted to verified DashClicks staff
- Role-based Access: Granular permission checking based on staff roles
- Session Management: Secure administrative session handling
- Audit Trail: Complete logging of all analytics access and operations
Data Privacy & Security
- Sensitive Data Protection: Secure handling of business intelligence data
- Access Logging: Comprehensive audit trail for compliance
- Rate Limiting: API rate limiting to prevent abuse
- Data Sanitization: Input validation and sanitization
📊 Common Query Parameters
Date Filtering
start_date(optional) - Start date for analytics period (default: 30 days ago)end_date(optional) - End date for analytics period (default: current date)product(optional) - Filter by specific product type (subscription analytics only)
Response Format
{
"success": true,
"message": "SUCCESS",
"data": {
"currentData": {
"total": 1500,
"data": [...] // Time series data points
},
"growthRate": 15.5 // Percentage growth rate
}
}
📝 Usage Notes
- All endpoints require DashClicks administrative authentication
- Date ranges default to last 30 days if not specified
- Growth rates are calculated as percentage change from previous period
- Time series data includes daily/monthly breakdowns where applicable
- Product filtering available for subscription-related analytics
- All monetary values are in cents (Stripe format)
- Error handling includes detailed error messages for debugging