Analytics Guide
Learn how to integrate and use LicenseChain analytics to gain insights into your license usage and business metrics.
Overview
LicenseChain provides comprehensive analytics endpoints to help you understand your business metrics, track license usage, monitor revenue, and analyze user behavior. All analytics endpoints require admin authentication.
What You'll Learn
Analytics Endpoints
- Overall statistics and metrics
- Revenue analytics and trends
- License usage analytics
- User growth and activity
Integration
- Fetching analytics data
- Filtering by time periods
- Building dashboards
- Exporting data for reporting
Authentication
All analytics endpoints require admin authentication. Make sure your API key has admin privileges.
Authorization: Bearer YOUR_ADMIN_API_KEY
Note: Only users with the ADMIN role can access analytics endpoints.
Regular users and sellers will receive a 403 Forbidden response.
Overall Statistics
Get Statistics
Retrieve high-level statistics about your LicenseChain account:
GET /v1/analytics/stats Authorization: Bearer YOUR_ADMIN_API_KEY
{
"users": {
"total": 1250
},
"licenses": {
"total": 5432,
"active": 4120,
"expired": 980,
"revoked": 332
},
"products": {
"total": 15
},
"revenue": {
"total": 125000.50
}
} Revenue Analytics
Get Revenue Data
Track revenue over time with daily breakdowns. Supports multiple time periods:
GET /v1/analytics/revenue?period=30d Authorization: Bearer YOUR_ADMIN_API_KEY
period=7d Last 7 days period=30d Last 30 days (default) period=90d Last 90 days period=1y Last year {
"period": "30d",
"startDate": "2024-11-01T00:00:00Z",
"endDate": "2024-12-01T00:00:00Z",
"dailyRevenue": {
"2024-11-01": 1250.00,
"2024-11-02": 980.50,
"2024-11-03": 2100.75,
...
},
"totalRevenue": 45678.25
} License Analytics
Get License Metrics
Track license creation, status changes, and product breakdown:
GET /v1/analytics/licenses?period=30d Authorization: Bearer YOUR_ADMIN_API_KEY
{
"period": "30d",
"startDate": "2024-11-01T00:00:00Z",
"endDate": "2024-12-01T00:00:00Z",
"dailyLicenses": {
"2024-11-01": {
"active": 45,
"expired": 2,
"suspended": 1
},
"2024-11-02": {
"active": 52,
"expired": 3,
"suspended": 0
},
...
},
"productBreakdown": [
{
"id": "product-1",
"name": "Premium License",
"count": 320
},
{
"id": "product-2",
"name": "Basic License",
"count": 180
}
]
} User Analytics
Get User Metrics
Track user registration, role distribution, and activity:
GET /v1/analytics/users?period=30d Authorization: Bearer YOUR_ADMIN_API_KEY
{
"period": "30d",
"startDate": "2024-11-01T00:00:00Z",
"endDate": "2024-12-01T00:00:00Z",
"dailyUsers": {
"2024-11-01": {
"ADMIN": 2,
"SELLER": 5,
"CUSTOMER": 23
},
"2024-11-02": {
"ADMIN": 2,
"SELLER": 6,
"CUSTOMER": 31
},
...
},
"totalUsers": 450,
"activeUsers": 320,
"inactiveUsers": 130
} Integration Examples
JavaScript/TypeScript
import { LicenseChainClient } from '@licensechain/sdk';
const client = new LicenseChainClient({
apiKey: 'your-admin-api-key',
baseUrl: 'https://api.licensechain.app'
});
// Get overall statistics
const stats = await client.get('/v1/analytics/stats');
console.log('Total users:', stats.users.total);
console.log('Total revenue:', stats.revenue.total);
// Get revenue analytics
const revenue = await client.get('/v1/analytics/revenue', {
params: { period: '30d' }
});
console.log('Daily revenue:', revenue.dailyRevenue);
// Get license analytics
const licenses = await client.get('/v1/analytics/licenses', {
params: { period: '7d' }
});
console.log('Product breakdown:', licenses.productBreakdown); Python
from licensechain import LicenseChainClient
client = LicenseChainClient(
api_key='your-admin-api-key',
base_url='https://api.licensechain.app'
)
# Get overall statistics
stats = client.get('/v1/analytics/stats')
print(f"Total users: {stats['users']['total']}")
print(f"Total revenue: {stats['revenue']['total']}")
# Get revenue analytics
revenue = client.get('/v1/analytics/revenue', params={'period': '30d'})
print(f"Daily revenue: {revenue['dailyRevenue']}")
# Get license analytics
licenses = client.get('/v1/analytics/licenses', params={'period': '7d'})
print(f"Product breakdown: {licenses['productBreakdown']}") cURL
# Get overall statistics curl -X GET "https://api.licensechain.app/v1/analytics/stats" \ -H "Authorization: Bearer YOUR_ADMIN_API_KEY" # Get revenue analytics curl -X GET "https://api.licensechain.app/v1/analytics/revenue?period=30d" \ -H "Authorization: Bearer YOUR_ADMIN_API_KEY" # Get license analytics curl -X GET "https://api.licensechain.app/v1/analytics/licenses?period=7d" \ -H "Authorization: Bearer YOUR_ADMIN_API_KEY"
Building Dashboards
Key Metrics to Display
- • Total Revenue: Use
/analytics/statsfor current total - • Revenue Trends: Use
/analytics/revenuefor daily breakdowns - • License Status: Track active, expired, and suspended licenses
- • User Growth: Monitor new user registrations over time
- • Product Performance: Compare license sales by product
Recommended Refresh Intervals
- • Real-time metrics: Refresh every 1-5 minutes
- • Daily summaries: Refresh every hour
- • Historical data: Refresh daily or weekly
- • Reports: Generate on-demand or schedule daily/weekly
Data Visualization Tips
- • Use line charts for revenue trends over time
- • Use bar charts for comparing product performance
- • Use pie charts for license status distribution
- • Use tables for detailed breakdowns and exports
- • Consider timezone handling for accurate date displays
Best Practices
✅ Cache Analytics Data
Analytics data doesn't change frequently. Cache responses for 5-15 minutes to reduce API calls and improve performance.
✅ Use Appropriate Time Periods
Choose time periods that match your use case. Use shorter periods (7d) for recent trends and longer periods (1y) for annual reports.
✅ Handle Errors Gracefully
Implement retry logic and fallback displays for when analytics endpoints are unavailable. Show cached data when possible.
✅ Secure Admin Credentials
Never expose admin API keys in client-side code. Always fetch analytics data from your backend server.
Next Steps
Now that you understand analytics, you can: