Call Tracking Metrics Integration
๐ Overviewโ
Call Tracking Metrics (CTM) integration provides call tracking analytics, phone number management, and webhook-based event handling for DashClicks campaigns. Unlike CallRail, CTM uses Basic Authentication (username/password) instead of API keys.
Key Features:
- Username/password authentication with automatic invalidation detection
- Account and sub-account hierarchy management
- Call tracking with detailed metrics and summaries
- Tracking number (tracker) management
- Webhook support for real-time call events
- Campaign preservation logic on disconnection
API Base URL: https://api.calltrackingmetrics.com/api/v1
Authentication Method: Basic Auth (username + password)
๐๏ธ Architectureโ
Directory Structureโ
external/Integrations/CallTrackingMetrics/
โโโ Controllers/
โ โโโ auth.js # Authentication and credential management
โ โโโ accounts.js # Account listing
โ โโโ calls.js # Call tracking and analytics
โ โโโ trackers.js # Tracking number management
โ โโโ webhooks.js # Webhook configuration
โโโ Providers/
โ โโโ auth-api.js # Authentication API calls
โ โโโ account-api.js # Account API calls
โ โโโ calls-api.js # Calls API calls
โ โโโ trackers-api.js # Tracker API calls
โ โโโ call-webhook.js # Webhook processing
โ โโโ get-headers.js # Auth header builder
โโโ Models/
โ โโโ keys.js # Credential storage model
โโโ Routes/
โ โโโ auth.js # Auth routes
โ โโโ accounts.js # Account routes
โ โโโ calls.js # Call routes
โ โโโ trackers.js # Tracker routes
โ โโโ webhooks.js # Webhook routes
โโโ index.js # Main router with error handling
Request Flowโ
sequenceDiagram
participant Client as DashClicks Frontend
participant Router as CTM Router
participant Controller as Controller
participant Provider as API Provider
participant CTM as Call Tracking Metrics API
participant MongoDB as MongoDB
Client->>Router: Request with JWT
Router->>Router: Verify authorization
Router->>Router: Set IDs (tokenId, accountId)
Router->>Controller: Route to controller
Controller->>MongoDB: Retrieve credentials
MongoDB-->>Controller: username, password
Controller->>Provider: API call with Basic Auth
Provider->>CTM: HTTP request
CTM-->>Provider: API response
Provider-->>Controller: Formatted data
Controller-->>Client: JSON response
๐๏ธ MongoDB Collectionsโ
integrations.calltrackingmetrics.keyโ
Purpose: Store CTM authentication credentials
Model: shared/models/calltrackingmetrics-key.js
Document Structure:
{
"_id": ObjectId("507f1f77bcf86cd799439011"),
"account_id": ObjectId("507f1f77bcf86cd799439012"),
"user": "ctm_username",
"password": "encrypted_password",
"access_key": "ctm_api_access_key",
"secret": "ctm_api_secret",
"token_invalidated": false,
"deleted": ISODate("2023-10-01T12:00:00Z"), // Soft delete
"createdAt": ISODate("2023-09-15T10:00:00Z"),
"updatedAt": ISODate("2023-10-01T12:00:00Z")
}
analytics.calltrackingmetrics.userconfigโ
Purpose: Link CTM account to DashClicks account for campaign tracking
Model: shared/models/analytics-calltrackingmetrics-userconfig.js
Document Structure:
{
"_id": ObjectId,
"account_id": ObjectId,
"token": "507f1f77bcf86cd799439011", // Reference to key document ID
"calltracking_account_id": "act_123456",
"calltracking_sub_account_id": "sub_789", // Optional sub-account
"createdAt": ISODate,
"updatedAt": ISODate
}
๐ Authenticationโ
Basic Authenticationโ
CTM uses username and password authentication (not API keys):
Authentication Endpoint: POST /api/v1/authentication
Request Body:
user={username}
password={password}
Response:
{
"access_key": "ctm_access_key_123",
"secret": "ctm_secret_456"
}
Subsequent API Calls: All API requests use Basic Auth header:
Authorization: Basic {base64(access_key:secret)}
Token Invalidation Detectionโ
Middleware: index.js error handler
Trigger: 401 Unauthorized response from CTM API
Actions:
- Set
token_invalidated: trueon all keys for account - Return
TOKEN_INVALIDATEDerror to client - User must re-authenticate with new credentials
๐ Call Tracking Metrics Hierarchyโ
graph TD
A[Account] --> B[Sub-Account Optional]
A --> C[Tracking Numbers]
B --> C
C --> D[Calls]
D --> E[Call Recordings]
D --> F[Call Metrics]
Hierarchy Componentsโ
- Account: Top-level organization (agency or business)
- Sub-Account: Optional child account for client segmentation
- Tracking Numbers: Phone numbers that track incoming calls
- Calls: Individual call records with attribution data
- Call Metrics: Aggregated analytics and reporting
๐ก API Endpointsโ
Authentication Endpointsโ
| Method | Endpoint | Description |
|---|---|---|
| POST | /v1/e/calltrackingmetrics/auth | Save credentials |
| POST | /v1/e/calltrackingmetrics/auth/config | Save user analytics config |
| DELETE | /v1/e/calltrackingmetrics/auth | Delete credentials |
Account Endpointsโ
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/e/calltrackingmetrics/:tokenId/accounts | List accounts |
| GET | /v1/e/calltrackingmetrics/:tokenId/accounts/:id | Get account details |
Call Endpointsโ
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/calls | List calls |
| GET | /v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/calls/summary | Get call summary |
| GET | /v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/calls/chart | Get timeline chart data |
Tracker Endpointsโ
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/trackers | List trackers |
| GET | /v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/trackers/:id | Get tracker details |
| POST | /v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/trackers | Create tracker |
| PUT | /v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/trackers/:id | Update tracker |
| DELETE | /v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/trackers/:id | Delete tracker |
Webhook Endpointsโ
| Method | Endpoint | Description |
|---|---|---|
| POST | /v1/e/calltrackingmetrics/:tokenId/webhook | Create webhook |
| POST | /v1/e/calltrackingmetrics/webhook/call-update | Receive call update webhook (public) |
๐ง Key Featuresโ
1. Credential Managementโ
- Username/password authentication
- Automatic token invalidation detection on 401 errors
- Soft delete with campaign preservation
- Notification system (FCM + Email)
2. Account Managementโ
- List all accounts with pagination
- Get individual account details
- Support for sub-accounts
3. Call Trackingโ
- Paginated call listing with filters
- Call summary analytics (answered, missed, duration)
- Timeline chart data for visualization
- Call status tracking (answered, failed, no-answer, canceled)
4. Tracking Numbersโ
- Create and manage tracking numbers
- Update tracker configuration
- Delete trackers
- List all trackers with pagination
5. Webhook Integrationโ
- Real-time call event notifications
- Webhook creation and management
- Call update event processing
๐ Integration with DashClicksโ
Campaign Trackingโ
User Config: Links CTM account to DashClicks campaigns
{
"account_id": ObjectId,
"calltracking_account_id": "act_123456",
"calltracking_sub_account_id": "sub_789" // Optional
}
Campaign Preservationโ
When deleting credentials:
- Global Delete (
?global=true): Disable all campaigns, delete config and credentials - Conditional Delete: Preserve credentials if active campaigns exist, only delete config
Notification Systemโ
FCM Notifications:
- Integration added:
project_addedtype - Integration disconnected:
integration_disconnectedtype
Email Notifications:
- Send to account owner
- Send to parent account if sub-account
- Configurable via user preferences
โ ๏ธ Important Differences from CallRailโ
| Feature | CallRail | Call Tracking Metrics |
|---|---|---|
| Authentication | API Key (Bearer token) | Username/Password (Basic Auth) |
| API Token Format | Static API key | access_key + secret from login |
| Hierarchy | Account โ Company โ Tracker | Account โ Sub-Account โ Tracker |
| Sub-Account Support | No | Yes (optional) |
| Header Format | Token token={key} | Basic {base64(key:secret)} |
| Token Refresh | N/A (static key) | Re-authenticate on 401 |
๐งช Error Handlingโ
Automatic Token Invalidationโ
Trigger: 401 Unauthorized from CTM API
Response:
{
"success": false,
"errno": 401,
"message": "TOKEN_INVALIDATED",
"code": "TOKEN_INVALIDATED"
}
System Actions:
- Mark all account keys as
token_invalidated: true - User must re-authenticate with new credentials
- Frontend redirected to authentication page
Campaign Preservationโ
Issue: Deleting credentials while campaigns active
Solution:
- Check for active campaigns before deletion
- If campaigns exist, only delete user config
- Keep credentials intact for campaign tracking
- Use
?global=trueto force complete removal
๐ Quick Startโ
1. Save Credentialsโ
POST /v1/e/calltrackingmetrics/auth
{
"username": "ctm_user",
"password": "ctm_pass"
}
2. Configure Analyticsโ
POST /v1/e/calltrackingmetrics/auth/config
{
"token": "507f1f77bcf86cd799439011",
"account_id": "act_123456",
"subaccount_id": "sub_789" // Optional
}
3. List Callsโ
GET /v1/e/calltrackingmetrics/{tokenId}/accounts/{accountId}/calls?page=1&limit=20
๐ Related Documentationโ
- Authentication: Credential Management
- Accounts: Account Management
- Calls: Call Tracking & Analytics
- Trackers: Tracking Number Management
- Webhooks: Webhook Configuration
- CTM API: Call Tracking Metrics API Documentation
โ ๏ธ Important Notesโ
- ๐ Basic Auth: Uses username/password, not API keys
- ๐ Token Refresh: Must re-authenticate on 401 errors
- ๐ Sub-Accounts: Optional sub-account support for client segmentation
- ๐๏ธ Soft Delete: Credentials marked as deleted, not removed
- ๐ Campaign Preservation: Keeps credentials if active campaigns exist
- ๐ Notifications: Email and FCM notifications on connect/disconnect
- ๐ฅ Parent Account: Sub-accounts send notifications to parent
- โ ๏ธ Global Delete: Use
?global=truequery param for complete removal