Dokumentation

Analytics & Monitoring

Track OTP performance, monitor usage patterns, and optimize your implementation with K-OTP analytics.

Overview

K-OTP provides comprehensive analytics to help you monitor performance, track usage patterns, and optimize your OTP implementation. Access real-time metrics and historical data through our dashboard and API.

Dashboard Analytics

Real-time Metrics

Monitor your OTP service performance in real-time:

  • Delivery rates across all methods (SMS, email, voice)
  • Response times and system performance
  • Success rates by country and carrier
  • Volume trends and usage patterns
  • Cost analysis and optimization insights

Key Performance Indicators

Track essential metrics for your OTP service:

interface OTPMetrics {
  deliveryRate: {
    overall: number;
    sms: number;
    email: number;
    voice: number;
  };
  averageDeliveryTime: {
    sms: number; // milliseconds
    email: number;
    voice: number;
  };
  verificationRate: number;
  costPerOTP: {
    sms: number;
    email: number;
    voice: number;
  };
}

Analytics API

Get Usage Statistics

Retrieve detailed usage statistics via API:

// Get overall usage stats
const response = await fetch('https://api.k-otp.dev/v1/analytics/usage', {
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json'
  },
  method: 'GET'
});

const stats = await response.json();

Response Format

{
  "period": {
    "start": "2024-01-01T00:00:00Z",
    "end": "2024-01-31T23:59:59Z"
  },
  "summary": {
    "total_sent": 50000,
    "total_delivered": 49500,
    "total_verified": 47000,
    "delivery_rate": 99.0,
    "verification_rate": 94.9,
    "total_cost": 2500.00,
    "average_cost_per_otp": 0.05
  },
  "by_method": {
    "sms": {
      "sent": 40000,
      "delivered": 39600,
      "verified": 37600,
      "cost": 2000.00
    },
    "email": {
      "sent": 8000,
      "delivered": 7900,
      "verified": 7500,
      "cost": 400.00
    },
    "voice": {
      "sent": 2000,
      "delivered": 2000,
      "verified": 1900,
      "cost": 100.00
    }
  }
}

Geographic Analytics

Country Performance

Monitor OTP performance by country:

// Get country-specific analytics
const countryStats = await fetch('https://api.k-otp.dev/v1/analytics/countries', {
  headers: { 'Authorization': `Bearer ${apiKey}` }
});

Response Data

{
  "countries": [
    {
      "code": "US",
      "name": "United States",
      "total_sent": 25000,
      "delivery_rate": 99.5,
      "average_cost": 0.04,
      "top_carriers": [
        {
          "name": "Verizon",
          "market_share": 35.2,
          "delivery_rate": 99.8
        },
        {
          "name": "AT&T",
          "market_share": 32.1,
          "delivery_rate": 99.6
        }
      ]
    }
  ]
}

Carrier Analysis

Track performance by carrier:

  • Delivery success rates per carrier
  • Average delivery times comparison
  • Cost variations between carriers
  • Market share and coverage data
  • Reliability scoring and recommendations

Time-based Analytics

Hourly Patterns

Analyze usage patterns throughout the day:

{
  "hourly_volume": [
    { "hour": 0, "count": 150 },
    { "hour": 1, "count": 89 },
    { "hour": 2, "count": 67 },
    // ... 24 hours
    { "hour": 23, "count": 134 }
  ],
  "peak_hours": [9, 10, 11, 18, 19, 20],
  "recommendations": {
    "optimize_for_peak": true,
    "suggested_scaling": "2x capacity during 9-11 AM and 6-8 PM"
  }
}

Track long-term usage trends:

  • Daily volume variations
  • Monthly growth patterns
  • Seasonal trends and predictions
  • Capacity planning recommendations
  • Cost optimization opportunities

Performance Monitoring

Response Time Analytics

Monitor API response times:

{
  "response_times": {
    "p50": 120,  // 50th percentile in ms
    "p95": 250,  // 95th percentile in ms
    "p99": 400,  // 99th percentile in ms
    "avg": 145   // average in ms
  },
  "by_endpoint": {
    "/send": { "avg": 150, "p95": 280 },
    "/verify": { "avg": 95, "p95": 180 },
    "/status": { "avg": 75, "p95": 120 }
  }
}

Uptime Monitoring

Track service availability:

  • Overall uptime percentage
  • Regional availability variations
  • Planned maintenance windows
  • Incident history and resolution times
  • SLA compliance reporting

Cost Analytics

Usage-based Billing

Monitor your costs and optimize spending:

{
  "cost_breakdown": {
    "total": 2500.00,
    "currency": "USD",
    "by_method": {
      "sms": {
        "total": 2000.00,
        "volume": 40000,
        "avg_cost": 0.05
      },
      "email": {
        "total": 400.00,
        "volume": 8000,
        "avg_cost": 0.05
      },
      "voice": {
        "total": 100.00,
        "volume": 2000,
        "avg_cost": 0.05
      }
    },
    "by_country": [
      {
        "country": "US",
        "cost": 1250.00,
        "volume": 25000,
        "avg_cost": 0.05
      }
    ]
  },
  "optimization_suggestions": [
    {
      "type": "carrier_optimization",
      "potential_savings": 150.00,
      "description": "Switch to carrier B for route XYZ"
    }
  ]
}

Cost Forecasting

Predict future costs based on usage patterns:

  • Monthly projections based on current trends
  • Seasonal adjustments for predictable patterns
  • Growth-based scaling estimates
  • Budget alerts and spending limits
  • Cost optimization recommendations

Custom Analytics

Event Tracking

Track custom events and metadata:

// Send OTP with custom tracking
const response = await fetch('https://api.k-otp.dev/v1/send', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${apiKey}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    to: '+1234567890',
    method: 'sms',
    type: 'verification',
    metadata: {
      campaign: 'signup_flow',
      ab_test: 'template_v2',
      user_segment: 'premium'
    }
  })
});

Custom Dashboards

Create personalized analytics views:

  • Filter by metadata fields
  • Custom time ranges and grouping
  • A/B testing results tracking
  • Conversion funnel analysis
  • Cohort analysis for user behavior

Alerts and Notifications

Threshold Alerts

Set up automated alerts for key metrics:

{
  "alerts": [
    {
      "name": "Low Delivery Rate",
      "metric": "delivery_rate",
      "threshold": 95.0,
      "condition": "below",
      "channels": ["email", "slack"]
    },
    {
      "name": "High Volume",
      "metric": "hourly_volume",
      "threshold": 1000,
      "condition": "above",
      "channels": ["email"]
    }
  ]
}

Alert Types

  • Delivery rate drops below threshold
  • Response time exceeds limits
  • Error rate increases significantly
  • Cost exceeds budget limits
  • Volume spikes or unusual patterns

Reporting

Automated Reports

Schedule regular analytics reports:

{
  "report_schedule": {
    "frequency": "weekly",
    "day": "monday",
    "time": "09:00",
    "timezone": "UTC",
    "recipients": ["[email protected]"],
    "format": "pdf",
    "sections": [
      "executive_summary",
      "usage_statistics",
      "cost_analysis",
      "performance_metrics"
    ]
  }
}

Export Options

Export analytics data for external analysis:

  • CSV exports for spreadsheet analysis
  • JSON API for programmatic access
  • PDF reports for stakeholder sharing
  • Real-time feeds for external dashboards
  • Data warehouse integration options

Integration with Analytics Tools

Google Analytics

Track OTP events in Google Analytics:

// Track OTP verification success
gtag('event', 'otp_verified', {
  event_category: 'authentication',
  event_label: 'login_flow',
  value: 1
});

Third-party Platforms

Integrate with popular analytics platforms:

  • Mixpanel for event tracking
  • Amplitude for user behavior analysis
  • Segment for data pipeline management
  • Datadog for infrastructure monitoring
  • New Relic for application performance

Privacy and Compliance

Data Retention

Analytics data retention policies:

  • Raw logs: 30 days
  • Aggregated metrics: 2 years
  • Summary reports: 7 years
  • GDPR compliance: Data deletion on request
  • Custom retention: Available for enterprise

Privacy Protection

Ensure user privacy in analytics:

  • Phone number hashing in reports
  • Metadata sanitization options
  • Anonymized reporting capabilities
  • GDPR-compliant data handling
  • Opt-out mechanisms for users

Best Practices

Monitoring Strategy

Effective analytics monitoring:

  1. Set baseline metrics for comparison
  2. Monitor trends rather than absolute numbers
  3. Set up proactive alerts for issues
  4. Regular review of performance patterns
  5. Optimize based on data insights

Performance Optimization

Use analytics to optimize performance:

  • Identify bottlenecks in delivery chains
  • Optimize carrier routing based on success rates
  • Adjust retry logic based on failure patterns
  • Scale infrastructure based on usage patterns
  • Reduce costs through intelligent routing

Troubleshooting

Use analytics for issue resolution:

  • Correlate issues across metrics
  • Identify patterns in failures
  • Track resolution effectiveness
  • Prevent future issues through monitoring
  • Document learnings for team knowledge