Skip to main content

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:

  1. Set token_invalidated: true on all keys for account
  2. Return TOKEN_INVALIDATED error to client
  3. 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โ€‹

  1. Account: Top-level organization (agency or business)
  2. Sub-Account: Optional child account for client segmentation
  3. Tracking Numbers: Phone numbers that track incoming calls
  4. Calls: Individual call records with attribution data
  5. Call Metrics: Aggregated analytics and reporting

๐Ÿ“ก API Endpointsโ€‹

Authentication Endpointsโ€‹

MethodEndpointDescription
POST/v1/e/calltrackingmetrics/authSave credentials
POST/v1/e/calltrackingmetrics/auth/configSave user analytics config
DELETE/v1/e/calltrackingmetrics/authDelete credentials

Account Endpointsโ€‹

MethodEndpointDescription
GET/v1/e/calltrackingmetrics/:tokenId/accountsList accounts
GET/v1/e/calltrackingmetrics/:tokenId/accounts/:idGet account details

Call Endpointsโ€‹

MethodEndpointDescription
GET/v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/callsList calls
GET/v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/calls/summaryGet call summary
GET/v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/calls/chartGet timeline chart data

Tracker Endpointsโ€‹

MethodEndpointDescription
GET/v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/trackersList trackers
GET/v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/trackers/:idGet tracker details
POST/v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/trackersCreate tracker
PUT/v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/trackers/:idUpdate tracker
DELETE/v1/e/calltrackingmetrics/:tokenId/accounts/:accountId/trackers/:idDelete tracker

Webhook Endpointsโ€‹

MethodEndpointDescription
POST/v1/e/calltrackingmetrics/:tokenId/webhookCreate webhook
POST/v1/e/calltrackingmetrics/webhook/call-updateReceive 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_added type
  • Integration disconnected: integration_disconnected type

Email Notifications:

  • Send to account owner
  • Send to parent account if sub-account
  • Configurable via user preferences

โš ๏ธ Important Differences from CallRailโ€‹

FeatureCallRailCall Tracking Metrics
AuthenticationAPI Key (Bearer token)Username/Password (Basic Auth)
API Token FormatStatic API keyaccess_key + secret from login
HierarchyAccount โ†’ Company โ†’ TrackerAccount โ†’ Sub-Account โ†’ Tracker
Sub-Account SupportNoYes (optional)
Header FormatToken token={key}Basic {base64(key:secret)}
Token RefreshN/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:

  1. Mark all account keys as token_invalidated: true
  2. User must re-authenticate with new credentials
  3. 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=true to 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

โš ๏ธ 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=true query param for complete removal
๐Ÿ’ฌ

Documentation Assistant

Ask me anything about the docs

Hi! I'm your documentation assistant. Ask me anything about the docs!

I can help you with:
- Code examples
- Configuration details
- Troubleshooting
- Best practices

Try asking: How do I configure the API?
09:30 AM