Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1c5f6cf
Add recharts library for data visualization
Mosas2000 May 30, 2026
aafc166
Add analytics endpoint with time-series data
Mosas2000 May 31, 2026
7f6b15e
Create analytics service for API integration
Mosas2000 May 31, 2026
378b902
Create main Analytics dashboard component
Mosas2000 May 31, 2026
3cf0366
Add analytics summary cards component
Mosas2000 May 31, 2026
13e1790
Add tip volume chart with line and bar views
Mosas2000 May 31, 2026
f04b1d8
Add top senders chart with rankings
Mosas2000 May 31, 2026
04e78c9
Add top recipients chart with rankings
Mosas2000 May 31, 2026
133abda
Add date range filter with presets
Mosas2000 May 31, 2026
f083749
Add data export functionality for CSV and JSON
Mosas2000 May 31, 2026
d56e881
Add analytics route to routes configuration
Mosas2000 May 31, 2026
9f57d83
Integrate analytics dashboard into app routing
Mosas2000 May 31, 2026
41e15c5
Add responsive styles for analytics dashboard
Mosas2000 May 31, 2026
623664c
Add comprehensive tests for analytics endpoint
Mosas2000 May 31, 2026
eb96603
Add comprehensive analytics feature documentation
Mosas2000 May 31, 2026
efa2686
Add error boundary for analytics components
Mosas2000 May 31, 2026
9bba2e5
Wrap analytics components with error boundaries
Mosas2000 May 31, 2026
e3c7726
Add loading skeleton for analytics dashboard
Mosas2000 May 31, 2026
63e73d3
Integrate loading skeleton into analytics component
Mosas2000 May 31, 2026
21a3343
Add mobile optimization and chart interactions to volume chart
Mosas2000 May 31, 2026
4c8ae4a
Add mobile optimization and interactions to top senders chart
Mosas2000 May 31, 2026
214c08a
Add mobile optimization and interactions to top recipients chart
Mosas2000 May 31, 2026
a527d8d
Add refresh button and auto-refresh functionality
Mosas2000 May 31, 2026
d33a1d5
Enhance mobile responsiveness for analytics summary cards
Mosas2000 May 31, 2026
e4e997b
Improve mobile responsiveness for date range filter
Mosas2000 May 31, 2026
1acc906
Enhance export functionality with loading states and mobile view
Mosas2000 May 31, 2026
2949a2b
Add keyboard shortcut for refresh functionality
Mosas2000 May 31, 2026
2226c51
fix(frontend): resolve blank screen, missing batchTipResults utility,…
Mosas2000 Jun 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
258 changes: 258 additions & 0 deletions ANALYTICS_FEATURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,258 @@
# Analytics Dashboard Feature

## Overview

The Analytics Dashboard provides comprehensive visualization and insights into tip statistics, trends, and platform activity. It includes interactive charts, date range filtering, and data export capabilities.

## Features

### Summary Cards

Four key metrics displayed prominently:
- **Total Tips**: Total number of tips sent on the platform
- **Total Volume**: Aggregate STX volume across all tips
- **Average Tip**: Mean tip amount in STX
- **Unique Users**: Combined count of unique senders and recipients

### Tip Volume Chart

Interactive time-series visualization showing:
- Number of tips per day
- Volume (STX) per day
- Dual Y-axis for tips count and volume
- Toggle between line and bar chart views
- Responsive design for mobile and desktop

### Top Senders

Horizontal bar chart and detailed rankings showing:
- Top 10 senders by volume
- Number of tips sent
- Total volume sent
- Abbreviated addresses with full address on hover

### Top Recipients

Horizontal bar chart and detailed rankings showing:
- Top 10 recipients by volume
- Number of tips received
- Total volume received
- Abbreviated addresses with full address on hover

### Date Range Filter

Flexible date filtering with:
- Custom start and end date selection
- Quick preset buttons (7, 30, 90 days)
- Apply and reset functionality
- Real-time data updates

### Data Export

Export analytics data in multiple formats:
- **CSV**: Time-series data for spreadsheet analysis
- **JSON**: Complete analytics data including all metrics

## API Endpoints

### GET /api/analytics

Returns comprehensive analytics data with optional date filtering.

**Query Parameters:**
- `startDate` (optional): ISO 8601 date string for range start
- `endDate` (optional): ISO 8601 date string for range end

**Response:**
```json
{
"summary": {
"totalTips": 1234,
"totalVolume": 5000000000,
"totalFees": 50000000,
"avgTipAmount": 4048582,
"uniqueSenders": 456,
"uniqueRecipients": 789
},
"topSenders": [
{
"address": "SP1ABC...",
"count": 50,
"volume": 250000000
}
],
"topRecipients": [
{
"address": "SP2DEF...",
"count": 75,
"volume": 300000000
}
],
"timeSeriesData": [
{
"date": "2024-01-15",
"count": 25,
"volume": 100000000
}
]
}
```

## Components

### Analytics.jsx
Main dashboard component that orchestrates all sub-components and manages state.

### AnalyticsSummary.jsx
Displays summary statistics in card format with icons.

### TipVolumeChart.jsx
Line/bar chart showing tip volume over time using Recharts.

### TopSendersChart.jsx
Horizontal bar chart and rankings for top senders.

### TopRecipientsChart.jsx
Horizontal bar chart and rankings for top recipients.

### DateRangeFilter.jsx
Date range selection with presets and custom dates.

### ExportData.jsx
Dropdown menu for exporting data in CSV or JSON format.

## Services

### analytics.js

Utility functions for:
- `fetchAnalytics(startDate, endDate)`: Fetch analytics data from API
- `fetchStats()`: Fetch basic statistics
- `formatAmount(amount)`: Format microSTX to STX
- `formatAddress(address)`: Abbreviate Stacks addresses
- `exportToCSV(data, filename)`: Export data as CSV
- `exportToJSON(data, filename)`: Export data as JSON

## Styling

### Responsive Design

- Mobile-first approach
- Grid layouts adapt to screen size
- Charts scale appropriately
- Touch-friendly controls

### Color Scheme

- Blue: Primary actions and tip counts
- Green: Volume and financial metrics
- Purple: Recipients
- Orange: User metrics

### Animations

- Smooth transitions on hover
- Loading states with pulse animation
- Slide-down menu animations
- Fade-in tooltips

## Usage

### Accessing the Dashboard

Navigate to `/analytics` or click "Analytics" in the main navigation.

### Filtering Data

1. Click on the date inputs to select custom dates
2. Or use preset buttons for common ranges
3. Click "Apply" to update the dashboard
4. Click "Reset" to clear filters

### Exporting Data

1. Click the "Export Data" button
2. Select CSV or JSON format
3. File downloads automatically with timestamp

### Chart Interactions

- Hover over data points for detailed tooltips
- Toggle between line and bar views
- Charts are fully responsive

## Technical Details

### Dependencies

- **recharts**: Chart library for data visualization
- **lucide-react**: Icon library
- **react-router-dom**: Routing

### Performance

- Lazy loading of chart components
- Efficient data aggregation on backend
- Memoized calculations
- Optimized re-renders

### Browser Support

- Modern browsers (Chrome, Firefox, Safari, Edge)
- Mobile browsers (iOS Safari, Chrome Mobile)
- Responsive down to 320px width

## Testing

Run analytics tests:
```bash
npm test -- analytics.test.js
```

Tests cover:
- API endpoint responses
- Date filtering
- Data structure validation
- Top senders/recipients limits
- Summary calculations

## Future Enhancements

Potential improvements:
- Real-time updates via WebSocket
- More chart types (pie, scatter)
- Advanced filtering (by address, amount range)
- Comparison views (period over period)
- Downloadable PDF reports
- Scheduled email reports
- Custom dashboard layouts
- Saved filter presets

## Troubleshooting

### Charts not displaying

- Check browser console for errors
- Verify API endpoint is accessible
- Ensure data is being returned

### Date filter not working

- Verify date format is correct
- Check that dates are within valid range
- Ensure API supports date parameters

### Export not downloading

- Check browser download settings
- Verify popup blocker is not interfering
- Ensure data exists to export

## Contributing

When adding new analytics features:
1. Update API endpoint if needed
2. Add corresponding tests
3. Update this documentation
4. Ensure responsive design
5. Add appropriate error handling
Loading
Loading