import { MailChannels } from "mailchannels-sdk";
const { MAILCHANNELS_API_KEY } = process.env;
if (!MAILCHANNELS_API_KEY) throw new Error("Set MAILCHANNELS_API_KEY before running");
const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);
const { data, error } = await mailchannels.metrics.engagement({
startTime: "2026-01-01T00:00:00Z",
endTime: "2026-01-31T23:59:59Z",
});
if (error) {
console.error("Get engagement metrics failed:", error);
process.exit(1);
}
console.log(data);import os
import sys
import mailchannels
if not os.environ.get("MAILCHANNELS_API_KEY"):
sys.exit("Set MAILCHANNELS_API_KEY before running")
# Retrieve daily open and click counts for a single campaign.
response = mailchannels.Metrics.engagement(
start_time="2026-01-01T00:00:00Z",
end_time="2026-01-31T23:59:59Z",
campaign_id="newsletter_jan_2026",
interval="day",
)
print(response)<?php
require_once __DIR__ . '/vendor/autoload.php';
use MailChannels\Client;
$api_key = getenv('MAILCHANNELS_API_KEY') or exit("Error: MAILCHANNELS_API_KEY is not set\n");
$client = new Client(apiKey: $api_key);
// Retrieve daily open and click counts for a single campaign.
$response = $client->metrics->engagement(
startTime: '2026-01-01T00:00:00Z',
endTime: '2026-01-31T23:59:59Z',
campaignId: 'newsletter_jan_2026',
interval: 'day',
);
print_r($response->toArray());curl --request GET \
--url https://api.mailchannels.net/tx/v1/metrics/engagement \
--header 'X-Api-Key: <x-api-key>'{
"buckets": {
"click": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"click_tracking_delivered": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"open": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"open_tracking_delivered": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"unique_click": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"unique_click_tracking_delivered": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"unique_open": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"unique_open_tracking_delivered": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
]
},
"click": 1,
"click_tracking_delivered": 1,
"open": 1,
"open_tracking_delivered": 1,
"end_time": "2023-11-07T05:31:56Z",
"start_time": "2023-11-07T05:31:56Z",
"unique_click": 1,
"unique_click_tracking_delivered": 1,
"unique_open": 1,
"unique_open_tracking_delivered": 1
}{
"errors": [
"<string>"
]
}Retrieve Engagement Metrics
Retrieve engagement metrics for messages sent from your account, including counts of open and click events. Supports optional filters for time range, and campaign ID.
import { MailChannels } from "mailchannels-sdk";
const { MAILCHANNELS_API_KEY } = process.env;
if (!MAILCHANNELS_API_KEY) throw new Error("Set MAILCHANNELS_API_KEY before running");
const mailchannels = new MailChannels(MAILCHANNELS_API_KEY);
const { data, error } = await mailchannels.metrics.engagement({
startTime: "2026-01-01T00:00:00Z",
endTime: "2026-01-31T23:59:59Z",
});
if (error) {
console.error("Get engagement metrics failed:", error);
process.exit(1);
}
console.log(data);import os
import sys
import mailchannels
if not os.environ.get("MAILCHANNELS_API_KEY"):
sys.exit("Set MAILCHANNELS_API_KEY before running")
# Retrieve daily open and click counts for a single campaign.
response = mailchannels.Metrics.engagement(
start_time="2026-01-01T00:00:00Z",
end_time="2026-01-31T23:59:59Z",
campaign_id="newsletter_jan_2026",
interval="day",
)
print(response)<?php
require_once __DIR__ . '/vendor/autoload.php';
use MailChannels\Client;
$api_key = getenv('MAILCHANNELS_API_KEY') or exit("Error: MAILCHANNELS_API_KEY is not set\n");
$client = new Client(apiKey: $api_key);
// Retrieve daily open and click counts for a single campaign.
$response = $client->metrics->engagement(
startTime: '2026-01-01T00:00:00Z',
endTime: '2026-01-31T23:59:59Z',
campaignId: 'newsletter_jan_2026',
interval: 'day',
);
print_r($response->toArray());curl --request GET \
--url https://api.mailchannels.net/tx/v1/metrics/engagement \
--header 'X-Api-Key: <x-api-key>'{
"buckets": {
"click": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"click_tracking_delivered": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"open": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"open_tracking_delivered": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"unique_click": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"unique_click_tracking_delivered": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"unique_open": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
],
"unique_open_tracking_delivered": [
{
"count": 1,
"period_start": "2023-11-07T05:31:56Z"
}
]
},
"click": 1,
"click_tracking_delivered": 1,
"open": 1,
"open_tracking_delivered": 1,
"end_time": "2023-11-07T05:31:56Z",
"start_time": "2023-11-07T05:31:56Z",
"unique_click": 1,
"unique_click_tracking_delivered": 1,
"unique_open": 1,
"unique_open_tracking_delivered": 1
}{
"errors": [
"<string>"
]
}Headers
Query Parameters
The beginning of the time range for retrieving message engagement metrics (inclusive). Formats: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SSZ. Defaults to one month ago if not provided.
The end of the time range for retrieving message engagement metrics (exclusive). Formats: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SSZ. Defaults to the current time if not provided.
The ID of the campaign to filter metrics by. If not provided, metrics for all campaigns will be returned.
The interval for aggregating metrics data. Allowed values:
- hour: Hourly breakdown
- day: Daily breakdown (default)
- week: Weekly breakdown
- month: Monthly breakdown
hour, day, week, month Response
Successfully retrieved engagement metrics
A series of metrics aggregations bucketed by time interval (e.g. hour, day)
Show child attributes
Show child attributes
Count of click events by recipients.
x >= 0Count of recipients of delivered messages with HTML content that contains tracked click URLs, where click tracking is enabled in the send request.
x >= 0Count of open events by recipients.
x >= 0Count of recipients of delivered messages with HTML content where open tracking was enabled in the send request.
x >= 0The end of the time range for retrieving message engagement metrics (exclusive).
The beginning of the time range for retrieving message engagement metrics (inclusive).
Count of distinct messages that had at least one click event. Unlike click, each message
is counted at most once regardless of how many links were clicked or how many times.
Use this to compute click rates without exceeding 100%.
x >= 0Count of distinct messages delivered with click tracking enabled (message-level, not recipient-level). Use as the denominator when computing unique click rates.
x >= 0Count of distinct messages that had at least one open event. Unlike open, each message
is counted at most once regardless of how many times its tracking pixel was fired.
Use this to compute open rates without exceeding 100%.
x >= 0Count of distinct messages delivered with open tracking enabled (message-level, not recipient-level). Use as the denominator when computing unique open rates.
x >= 0Was this page helpful?

