Metrics, Dashboards & Analytics
Relevant source files
The following files were used as context for generating this wiki page:
- server/polar/metrics/endpoints.py
- clients/apps/web/src/components/DashboardOverview/OverviewSection.tsx
- clients/apps/web/src/components/Metrics/dashboards/DashboardsListSidebar.tsx
- clients/apps/web/src/components/DashboardOverview/MetricSelectorModal.tsx
- server/polar/organization_review/analyzer.py
- DEVELOPMENT.md
The Polar Metrics and Analytics system provides real-time visibility into financial performance, subscription health, and organizational risk. It is a full-stack implementation comprising a FastAPI backend for data aggregation, a React-based frontend for visualization, and a customizable dashboard system that allows users to track specific Key Performance Indicators (KPIs).
The system serves both as a business intelligence tool for merchants and a compliance tool for the Polar platform. It tracks critical values such as revenue, refund rates, and dispute history to ensure platform integrity and merchant success.
System Architecture
The analytics architecture follows a tiered approach where raw event data is processed and exposed via a centralized metrics service. The frontend consumes this data through segmented time intervals (e.g., daily, weekly) to render interactive charts and summaries.
Data Flow Overview
This diagram illustrates the flow of data from the backend storage through the Metrics Service to the React frontend components.
Sources: server/polar/metrics/endpoints.py:53-125, clients/apps/web/src/components/DashboardOverview/OverviewSection.tsx:68-74, DEVELOPMENT.md:12-32
Backend Implementation
The backend is centered around the /v1/metrics router, which provides endpoints for querying time-series data, exporting reports, and managing custom dashboards.
Core Metrics API
The system provides a highly configurable query interface allowing filtering by date range, timezone, and granularity.
| Endpoint | Method | Description |
|---|---|---|
/ | GET | Retrieves time-series metric data with support for filtering by Organization, Product, Billing Type, and Customer. |
/export | GET | Generates a CSV export of the requested metrics for a specific time period. |
/limits | GET | Returns the minimum/maximum allowed dates and interval constraints for queries. |
/dashboards | GET/POST | Lists or creates user-defined metric dashboards. |
Sources: server/polar/metrics/endpoints.py:53-307
Metric Definition and Validation
Metrics are categorized by slugs (e.g., refund_rate, revenue). The backend validates these slugs against a predefined METRICS list to ensure query performance and data accuracy.
# Validation of metric slugs in endpoints.py
if metrics is not None:
valid_slugs = {m.slug for m in METRICS}
invalid_slugs = set(metrics) - valid_slugs
if invalid_slugs:
raise PolarRequestValidationError([...])
Sources: server/polar/metrics/endpoints.py:102-115
Dashboard and UI Components
The frontend provides an interactive "Overview" section and a sidebar for navigating between different dashboard views.
Dashboard Sidebar
The DashboardsListSidebar component manages the navigation between default analytics views and custom user-created dashboards.
- Default Dashboards: Pre-configured views provided by the platform.
- Custom Dashboards: Created by users through the
MetricDashboardEditorContentcomponent, allowing up to 10 metrics per view. - Metric Formatting: Displays the number of metrics contained within a specific dashboard.
Sources: clients/apps/web/src/components/Metrics/dashboards/DashboardsListSidebar.tsx:43-98
Overview Customization
The OverviewSection allows users to pin a specific set of 5 metrics to their main dashboard. This configuration is persisted in the organization's feature_settings.
The sequence shows the process of customizing the overview dashboard metrics using a drag-and-drop interface.
Sources: clients/apps/web/src/components/DashboardOverview/OverviewSection.tsx:40-66, clients/apps/web/src/components/DashboardOverview/MetricSelectorModal.tsx:238-258
Drag-and-Drop Editor
Metric selection and ordering is implemented using @dnd-kit. Users can select metrics from categorized groups (e.g., "Financial", "Subscriptions") and arrange them in a vertical sortable list.
Sources: clients/apps/web/src/components/DashboardOverview/MetricSelectorModal.tsx:75-100
Analytics and Risk Assessment
Polar uses the metrics system not only for merchant insights but also for automated risk analysis. The ReviewAnalyzer utilizes specific metric thresholds to flag organizations for human review.
Key Performance and Risk Indicators
The system calculates specific ratios to determine organizational health.
| Metric | Critical Threshold | Description |
|---|---|---|
| Refund Rate | > 15% | Percentage of succeeded payments that resulted in refunds. |
| Dispute Count | > 0 | Absolute count of chargebacks or payment disputes. |
| Risk Score | P50 / P90 | Statistical risk scores provided by payment rails (e.g., Stripe Radar). |
| Auth Rate | < 80% | Percentage of payment authorizations that were successful. |
Sources: server/polar/organization_review/analyzer.py:59-75, server/polar/organization_review/analyzer.py:651-665
Volume-Weighted Analysis
The system incorporates a "Minimum volume requirement" logic. Rate-based metrics (like refund rates) are treated as inconclusive if the organization has fewer than 10 succeeded payments, preventing statistical noise from triggering false positives for new merchants.
Sources: server/polar/organization_review/analyzer.py:77-85, server/polar/organization_review/analyzer.py:431-438
Summary
The Metrics and Analytics system in Polar is an integrated framework that provides both business intelligence for users and risk mitigation for the platform. By combining a flexible FastAPI backend with a drag-and-drop React frontend, Polar enables merchants to build custom dashboards while maintaining rigorous oversight through automated metric analyzers.