AutoDialerCallerIdStat Model
Overview
Tracks usage statistics for each Caller ID (DID) within a campaign's pool. Provides insights into call distribution and success rates per number.
Table: auto_dialer_caller_id_stats
Model: App\Models\AutoDialerCallerIdStat
Database Schema
| Column | Type | Nullable | Default | Description |
|---|---|---|---|---|
id | bigint unsigned | No | auto | Primary key |
campaign_id | bigint unsigned | No | - | FK to auto_dialer_campaigns |
did_number_id | bigint unsigned | No | - | FK to did_numbers |
total_calls | int unsigned | No | 0 | Calls placed from this DID that have ended (completed + failed) |
completed_calls | int unsigned | No | 0 | Successfully completed calls |
failed_calls | int unsigned | No | 0 | Failed calls |
last_used_at | timestamp | Yes | null | When this DID was last used |
created_at | timestamp | Yes | null | Creation timestamp |
updated_at | timestamp | Yes | null | Last update timestamp |
Indexes
- Primary:
id - Unique:
campaign_id+did_number_id(one stats record per DID per campaign) - Foreign keys:
campaign_id→auto_dialer_campaigns,did_number_id→did_numbers, bothON DELETE CASCADE
Relationships
Belongs To
$stat->campaign() → AutoDialerCampaign
$stat->didNumber() → DidNumber
Methods
Attribute Accessors
// Calculate success rate percentage
$stat->success_rate → float (e.g., 90.0)
Business Logic Methods
// Record a completed call
$stat->recordCompleted(): void
// Increments total_calls and completed_calls
// Updates last_used_at
// Record a failed call
$stat->recordFailed(): void
// Increments total_calls and failed_calls
// Updates last_used_at
Usage Examples
Getting Statistics
use App\Models\AutoDialerCampaign;
$campaign = AutoDialerCampaign::with('callerIdStats.didNumber')->find(1);
foreach ($campaign->callerIdStats as $stat) {
echo "Number: {$stat->didNumber->phone_number}\n";
echo "Total Calls: {$stat->total_calls}\n";
echo "Success Rate: {$stat->success_rate}%\n";
echo "Last Used: {$stat->last_used_at}\n";
}
Aggregate Statistics
// Total calls across all Caller IDs
$totalCalls = $campaign->callerIdStats->sum('total_calls');
// Average success rate
$avgSuccessRate = $campaign->callerIdStats->avg('success_rate');
// Most used Caller ID
$mostUsed = $campaign->callerIdStats->sortByDesc('total_calls')->first();
API Response Format
{
"campaign_id": 9,
"total_calls": 150,
"strategy": "round_robin",
"stats": [
{
"did_id": 1,
"phone_number": "+12127773456",
"friendly_name": "Sales Line 1",
"total_calls": 50,
"completed_calls": 45,
"failed_calls": 5,
"success_rate": 90.0,
"last_used_at": "2026-04-10T14:30:00Z"
}
]
}
Recording Statistics
CallerIdPoolService creates one row per pool DID, with all counters at 0, when a campaign's Caller ID pool is created or synced, and deletes the rows of DIDs removed from the pool. The service's getCallerIdStats() builds the API response shown above.
AutoDialerCallSession keeps the caller ID each call was placed from (caller_id, caller_did_id, set from the dialer worker's initiate-call request). When a session's status first changes to completed or failed, an updated model hook on AutoDialerCallSession calls recordCompleted() or recordFailed() on the stats row of that campaign and caller_did_id. Every path that finalises a session (Cloudonix call-status webhooks, the dialer-worker status and disposition endpoints, AMD actions) goes through that hook, and a cache key per session (kept 7 days) makes sure a call is counted only once, even when a webhook is retried or a later update changes the status again. Each call attempt is its own session, so a busy or no-answer attempt that is retried counts as one failed call, and the retry is counted separately.
Not counted: sessions with no caller_did_id (no pool number), sessions whose DID has no stats row (removed from the pool), and sessions marked failed in bulk when a campaign is paused or stopped (a query update that does not fire model hooks).
Analytics Queries
// Caller IDs with more failed than completed calls
$problematic = AutoDialerCallerIdStat::with('didNumber')
->where('campaign_id', $campaignId)
->whereColumn('failed_calls', '>', 'completed_calls')
->get();
// Usage distribution
$distribution = AutoDialerCallerIdStat::where('campaign_id', $campaignId)
->select('did_number_id', 'total_calls')
->get();
success_rate is an accessor (completed_calls / total_calls * 100, rounded to 2 decimals, 0 when there are no calls), not a column, so you cannot sort or filter on it in SQL.
Related Models
- AutoDialerCampaign - Parent campaign
- AutoDialerCampaignCallerId - Pool assignment
- DidNumber (
App\Models\DidNumber) - The phone number details