# Analytics API

> Campaign performance metrics and reporting via the WAFlow API

Source: https://edesy.in/docs/waflow/api/analytics

Get detailed performance metrics for your campaigns and overall workspace analytics.

## Campaign Analytics

Get detailed analytics for a specific campaign.

```http
GET /api/analytics/campaigns/{id}
```

**Path Parameters:**

| Parameter | Type | Description |
|-----------|------|-------------|
| id | number | The campaign ID |

**Response:**
```json
{
  "campaignId": 1,
  "campaignName": "Summer Sale Campaign",
  "totalSent": 100,
  "totalDelivered": 95,
  "totalRead": 80,
  "totalReplied": 25,
  "totalFailed": 5,
  "deliveryRate": 95.0,
  "openRate": 84.21,
  "replyRate": 31.25,
  "failureRate": 5.0,
  "timeline": [
    {
      "date": "2025-01-01",
      "sent": 100,
      "delivered": 95,
      "read": 80,
      "replied": 25
    }
  ]
}
```

**Metrics Explained:**

| Metric | Description |
|--------|-------------|
| totalSent | Messages successfully sent to WhatsApp |
| totalDelivered | Messages delivered to recipient devices |
| totalRead | Messages opened/read by recipients |
| totalReplied | Messages that received a reply |
| totalFailed | Messages that failed to send |
| deliveryRate | (delivered / sent) * 100 |
| openRate | (read / delivered) * 100 |
| replyRate | (replied / read) * 100 |
| failureRate | (failed / sent) * 100 |

**cURL Example:**
```bash
curl -X GET "https://waflow.edesy.in/api/analytics/campaigns/1" \
  -H "Content-Type: application/json" \
  -b cookies.txt
```

**JavaScript Example:**
```javascript
const campaignId = 1;
const response = await fetch(`https://waflow.edesy.in/api/analytics/campaigns/${campaignId}`, {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
  },
  credentials: 'include'
});

const analytics = await response.json();
console.log(`Delivery Rate: ${analytics.deliveryRate}%`);
console.log(`Open Rate: ${analytics.openRate}%`);
```

---

## Dashboard Analytics

Get overall workspace analytics and recent campaign performance.

```http
GET /api/analytics/dashboard
```

**Response:**
```json
{
  "totalCampaigns": 25,
  "totalContacts": 1500,
  "totalMessagesSent": 5000,
  "avgDeliveryRate": 94.5,
  "avgOpenRate": 78.2,
  "recentCampaigns": [
    {
      "id": 1,
      "name": "Summer Sale",
      "status": "completed",
      "deliveryRate": 95.0
    },
    {
      "id": 2,
      "name": "Welcome Series",
      "status": "active",
      "deliveryRate": 92.3
    }
  ]
}
```

**Dashboard Metrics:**

| Metric | Description |
|--------|-------------|
| totalCampaigns | Total campaigns created in workspace |
| totalContacts | Total contacts in workspace |
| totalMessagesSent | Lifetime messages sent |
| avgDeliveryRate | Average delivery rate across all campaigns |
| avgOpenRate | Average open rate across all campaigns |
| recentCampaigns | Last 5 campaigns with performance data |

**cURL Example:**
```bash
curl -X GET "https://waflow.edesy.in/api/analytics/dashboard" \
  -H "Content-Type: application/json" \
  -b cookies.txt
```

---

## Understanding WhatsApp Message Status

WhatsApp provides detailed delivery status for each message:

| Status | Description |
|--------|-------------|
| `sent` | Message sent to WhatsApp servers |
| `delivered` | Message delivered to recipient's device |
| `read` | Message opened by recipient (if read receipts enabled) |
| `failed` | Message failed to send |

### Delivery Funnel

```
Sent (100) → Delivered (95) → Read (80) → Replied (25)
         ↓
      Failed (5)
```

---

## Timeline Data

The `timeline` array provides day-by-day breakdown:

```json
{
  "timeline": [
    {
      "date": "2025-01-01",
      "sent": 50,
      "delivered": 48,
      "read": 40,
      "replied": 12
    },
    {
      "date": "2025-01-02",
      "sent": 50,
      "delivered": 47,
      "read": 40,
      "replied": 13
    }
  ]
}
```

This helps you:
- Track campaign performance over time
- Identify peak engagement periods
- Optimize future campaign timing

---

## Benchmarks

Typical WhatsApp campaign benchmarks:

| Metric | Good | Average | Needs Improvement |
|--------|------|---------|-------------------|
| Delivery Rate | >95% | 90-95% | <90% |
| Open Rate | >80% | 60-80% | <60% |
| Reply Rate | >20% | 10-20% | <10% |

> **Tip:** WhatsApp typically has higher engagement rates than email. Aim for 80%+ open rates.

---

## Improving Campaign Performance

Based on analytics, consider:

1. **Low delivery rate** - Check phone number quality, verify WhatsApp accounts
2. **Low open rate** - Review template content, timing, and relevance
3. **Low reply rate** - Add clear calls-to-action, personalize messages
4. **High failure rate** - Audit contact list quality, check for invalid numbers
