📊 Metrics module Email API
This module allows you to retrieve metrics for messages sent from your account.
Engagement method
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.
Usage
import { MailChannelsClient, Metrics } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const metrics = new Metrics(mailchannels)
const { data, error } = await metrics.engagement()import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.metrics.engagement()Params
optionsMetricsOptionsoptional: Optional filter options.startTimestringoptional: The beginning of the time range for retrieving message engagement metrics (inclusive). Formats:YYYY-MM-DDorYYYY-MM-DDTHH:MM:SSZ. Defaults to one month ago if not provided.endTimestringoptional: The end of the time range for retrieving message engagement metrics (exclusive). Formats:YYYY-MM-DDorYYYY-MM-DDTHH:MM:SSZ. Defaults to the current time if not provided.campaignIdstringoptional: The ID of the campaign to filter metrics by. If not provided, metrics for all campaigns will be returned.interval"hour" | "day" | "week" | "month"optional: The interval for aggregating metrics data. Defaults today.
Response
dataMetricsEngagement | nullnullablebucketsobjectguaranteed: A series of metrics aggregations bucketed by time interval (e.g. hour, day).clickMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
clickTrackingDeliveredMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
openMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
openTrackingDeliveredMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
clicknumberguaranteedclickTrackingDeliverednumberguaranteedendTimestringguaranteedopennumberguaranteedopenTrackingDeliverednumberguaranteedstartTimestringguaranteed
errorstring | nullnullable
Performance method
Retrieve performance metrics for messages sent from your account, including counts of processed, delivered, hard-bounced events. Supports optional filters for time range, and campaign ID.
Usage
import { MailChannelsClient, Metrics } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const metrics = new Metrics(mailchannels)
const { data, error } = await metrics.performance()import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.metrics.performance()Params
optionsMetricsOptionsoptional: Optional filter options.startTimestringoptional: The beginning of the time range for retrieving message performance metrics (inclusive). Formats:YYYY-MM-DDorYYYY-MM-DDTHH:MM:SSZ. Defaults to one month ago if not provided.endTimestringoptional: The end of the time range for retrieving message performance metrics (exclusive). Formats:YYYY-MM-DDorYYYY-MM-DDTHH:MM:SSZ. Defaults to the current time if not provided.campaignIdstringoptional: The ID of the campaign to filter metrics by. If not provided, metrics for all campaigns will be returned.interval"hour" | "day" | "week" | "month"optional: The interval for aggregating metrics data. Defaults today.
Response
dataMetricsPerformance | nullnullablebouncednumberguaranteed: Count of messages bounced during the specified time range.bucketsobjectguaranteed: A series of metrics aggregations bucketed by time interval (e.g. hour, day).bouncedMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
deliveredMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
processedMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
deliverednumberguaranteed: Count of messages delivered during the specified time range.endTimestringguaranteed: The end of the time range for retrieving message performance metrics (exclusive).processednumberguaranteed: Count of messages processed during the specified time range.startTimestringguaranteed: The beginning of the time range for retrieving message performance metrics (inclusive).
errorstring | nullnullable
Recipient Behaviour method
Retrieve recipient behaviour metrics for messages sent from your account, including counts of unsubscribed events. Supports optional filters for time range, and campaign ID.
Usage
import { MailChannelsClient, Metrics } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const metrics = new Metrics(mailchannels)
const { data, error } = await metrics.recipientBehaviour()import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.metrics.recipientBehaviour()Params
optionsMetricsOptionsoptional: Optional filter options.startTimestringoptional: The beginning of the time range for retrieving recipient behaviour metrics (inclusive). Formats:YYYY-MM-DDorYYYY-MM-DDTHH:MM:SSZ. Defaults to one month ago if not provided.endTimestringoptional: The end of the time range for retrieving recipient behaviour metrics (exclusive). Formats:YYYY-MM-DDorYYYY-MM-DDTHH:MM:SSZ. Defaults to the current time if not provided.campaignIdstringoptional: The ID of the campaign to filter metrics by. If not provided, metrics for all campaigns will be returned.interval"hour" | "day" | "week" | "month"optional: The interval for aggregating metrics data. Defaults today.
Response
dataMetricsRecipientBehaviour | nullnullablebucketsobjectguaranteed: A series of metrics aggregations bucketed by time interval (e.g. hour, day).unsubscribeDeliveredMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
unsubscribedMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
endTimestringguaranteed: The end of the time range for retrieving recipient behaviour metrics (exclusive).startTimestringguaranteed: The beginning of the time range for retrieving recipient behaviour metrics (inclusive).unsubscribeDeliverednumberguaranteed: Count of recipients of delivered messages that include at least one of the unsubscribe link or unsubscribe headers. Since the unsubscribe feature requires exactly one recipient per message, this count also represents the total number of delivered messages.unsubscribednumberguaranteed: Count of unsubscribed events by recipients.
errorstring | nullnullable
Volume method
Retrieve volume metrics for messages sent from your account, including counts of processed, delivered and dropped events. Supports optional filters for time range and campaign ID.
Usage
import { MailChannelsClient, Metrics } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const metrics = new Metrics(mailchannels)
const { data, error } = await metrics.volume()import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.metrics.volume()Params
optionsMetricsOptionsoptional: Optional filter options.startTimestringoptional: The beginning of the time range for retrieving message volume metrics (inclusive). Formats:YYYY-MM-DDorYYYY-MM-DDTHH:MM:SSZ. Defaults to one month ago if not provided.endTimestringoptional: The end of the time range for retrieving message volume metrics (exclusive). Formats:YYYY-MM-DDorYYYY-MM-DDTHH:MM:SSZ. Defaults to the current time if not provided.campaignIdstringoptional: The ID of the campaign to filter metrics by. If not provided, metrics for all campaigns will be returned.interval"hour" | "day" | "week" | "month"optional: The interval for aggregating metrics data. Defaults today.
Response
dataMetricsVolume | nullnullablebucketsobjectguaranteed: A series of metrics aggregations bucketed by time interval (e.g. hour, day).deliveredMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
droppedMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
processedMetricsBucket[]guaranteedcountnumberguaranteed: The number of events or occurrences aggregated within this time period.periodStartstringguaranteed: The starting date and time of the time period this bucket represents.
deliverednumberguaranteed: Count of messages delivered during the specified time range.droppednumberguaranteed: Count of messages dropped during the specified time range.endTimestringguaranteed: The end of the time range for retrieving message volume metrics (exclusive).processednumberguaranteed: Count of messages processed during the specified time range.startTimestringguaranteed: The beginning of the time range for retrieving message volume metrics (inclusive).
errorstring | nullnullable
Usage method
Retrieves usage statistics during the current billing period.
Usage
import { MailChannelsClient, Metrics } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const metrics = new Metrics(mailchannels)
const { data, error } = await metrics.usage()import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.metrics.usage()Response
usageobject | nullnullableendDatestringguaranteed: The end date of the current billing period (ISO 8601 format).startDatestringguaranteed: The start date of the current billing period (ISO 8601 format).totalnumberguaranteed: The total usage for the current billing period.
errorstring | nullnullable
Senders method
Retrieves a list of senders, either sub-accounts or campaigns, with their associated message metrics. Sorted by total # of sent messages (processed + dropped). Supports optional filter for time range, and optional settings for limit, offset, and sort order. Note: senders without any messages in the given time range will not be included in the results. The default time range is from one month ago to now, and the default sort order is descending.
Usage
import { MailChannelsClient, Metrics } from 'mailchannels-sdk'
const mailchannels = new MailChannelsClient('your-api-key')
const metrics = new Metrics(mailchannels)
const { data, error } = await metrics.senders("campaigns")import { MailChannels } from 'mailchannels-sdk'
const mailchannels = new MailChannels('your-api-key')
const { data, error } = await mailchannels.metrics.senders("campaigns")Params
typeMetricsSendersTyperequired: The type of senders to retrieve metrics for. Can be eithersub-accountsorcampaigns.optionsMetricsSendersOptionsoptional: Optional filter options.startTimestringoptional: The beginning of the time range for retrieving top senders metrics (inclusive). Formats:YYYY-MM-DDorYYYY-MM-DDTHH:MM:SSZ. Defaults to one month ago if not provided.endTimestringoptional: The end of the time range for retrieving top senders metrics (exclusive). Formats:YYYY-MM-DDorYYYY-MM-DDTHH:MM:SSZ. Defaults to the current time if not provided.limitnumberoptional: The maximum number of senders to return. Possible values are 1 to 1000. Defaults to 10 if not provided.offsetnumberoptional: The number of senders to skip before returning results. Defaults to 0 if not provided.sortOrder"asc" | "desc"optional: The order in which to sort the results, based on total messages (processed + dropped). Defaults todescif not provided.
Response
dataMetricsSenders | nullnullableendTimestringguaranteedlimitnumberguaranteedoffsetnumberguaranteedsendersobject[]guaranteedbouncednumberguaranteeddeliverednumberguaranteeddroppednumberguaranteednamestringguaranteedprocessednumberguaranteed
startTimestringguaranteedtotalnumberguaranteed: The total number of senders in this category that sent messages in the given time range.
errorstring | nullnullable
Type declarations
class Metrics {
constructor (protected mailchannels: MailChannelsClient);
async engagement (options?: MetricsOptions): Promise<MetricsEngagementResponse>;
async performance (options?: MetricsOptions): Promise<MetricsPerformanceResponse>;
async recipientBehaviour (options?: MetricsOptions): Promise<MetricsRecipientBehaviourResponse>;
async volume (options?: MetricsOptions): Promise<MetricsVolumeResponse>;
async usage (): Promise<MetricsUsageResponse>;
async senders (type: MetricsSendersType, options?: MetricsSendersOptions): Promise<MetricsSendersResponse>;
}All type declarations
Responses
interface DataResponse<T> {
data: T | null;
error: string | null;
}Shared metrics type declarations
interface MetricsOptions {
startTime?: string;
endTime?: string;
campaignId?: string;
interval?: "hour" | "day" | "week" | "month";
}interface MetricsBucket {
count: number;
periodStart: string;
}Engagement type declarations
interface MetricsEngagement {
buckets: {
click: MetricsBucket[];
clickTrackingDelivered: MetricsBucket[];
open: MetricsBucket[];
openTrackingDelivered: MetricsBucket[];
};
click: number;
clickTrackingDelivered: number;
endTime: string;
open: number;
openTrackingDelivered: number;
startTime: string;
}type MetricsEngagementResponse = DataResponse<MetricsEngagement>;Performance type declarations
interface MetricsPerformance {
bounced: number;
buckets: {
bounced: MetricsBucket[];
delivered: MetricsBucket[];
processed: MetricsBucket[];
};
delivered: number;
endTime: string;
processed: number;
startTime: string;
}type MetricsPerformanceResponse = DataResponse<MetricsPerformance>;Recipient Behaviour type declarations
interface MetricsRecipientBehaviour {
buckets: {
unsubscribeDelivered: MetricsBucket[];
unsubscribed: MetricsBucket[];
};
endTime: string;
startTime: string;
unsubscribeDelivered: number;
unsubscribed: number;
}type MetricsRecipientBehaviourResponse = DataResponse<MetricsRecipientBehaviour>;Volume type declarations
interface MetricsVolume {
buckets: {
delivered: MetricsBucket[];
dropped: MetricsBucket[];
processed: MetricsBucket[];
};
delivered: number;
dropped: number;
endTime: string;
processed: number;
startTime: string;
}type MetricsVolumeResponse = DataResponse<MetricsVolume>;Usage type declarations
type MetricsUsageResponse = DataResponse<{
endDate: string;
startDate: string;
total: number;
}>;Senders type declarations
type MetricsSendersType = "sub-accounts" | "campaigns";interface MetricsSendersOptions {
startTime?: string;
endTime?: string;
limit?: number;
offset?: number;
sortOrder?: "asc" | "desc";
}interface MetricsSenders {
endTime: string;
limit: number;
offset: number;
senders: {
bounced: number;
delivered: number;
dropped: number;
name: string;
processed: number;
}[];
startTime: string;
total: number;
}type MetricsSendersResponse = DataResponse<MetricsSenders>;Source
Source • Playground • Docs