How to replicate the UI Campaign Analytics using the API

Rebuild your own analytics tracking using Smartlead's API

The 2 APIs in question here - API 1 and API 2

Lets crack down on what all the values in the return body mean:

Open count: open_count

Type: Number
Description: The open count refers to the total number of times an email has been opened by all recipients. It includes multiple opens from the same recipient if they open the email multiple times.


Unique open count: unique_open_count

Type: Number
Description: The unique open count represents the number of individual leads who have opened the email at least once. It counts only one open per lead, even if the lead opens the email multiple times.


Unique sent count: unique_sent_count

Type: Number
Description: The unique sent count denotes the total number of unique leads to whom the email was sent. It counts each lead only once, regardless of how many times they received the email due to any email forwarding or distribution lists.


Click count: click_count

Type: Number
Description: The click count refers to the total number of times recipients clicked on a link or a CTA (Call-to-Action) within the email. It includes all clicks, even if multiple clicks are made by the same recipient.


Unique click count: unique_click_count
Type: Number
Description: The unique click count measures the number of individual leads who clicked on any link or CTA within the email at least once. It counts only one click per lead, even if the lead clicked multiple links.


Reply count: reply_count

Type: Number
Description: The reply count indicates the total number of direct replies received in response to the email campaign per sequence. It only includes replies that are received within the context of the email campaign and excludes threaded replies or responses that are done in the master inbox.


Number of sequences: sequence_count

Type: Number
Description: The number of sequences refers to the total count of individual email sequences included in the campaign.


Total count: total_count

Type: Number
Description: The total count represents the number of leads or recipients included in the email campaign.


Drafted count: drafted_count

Type: Number
Description: The drafted count represents the number of remaining sequences in the email campaign that are yet to be sent to the leads. Each sequence corresponds to a specific set of emails scheduled to be sent at predetermined intervals or based on certain triggers. For instance, if an email campaign consists of 5 sequences and targets 100 leads, and only 1 sequence has been sent, then the drafted count will be calculated as the number of unsent sequences, which is 4. In this example, the drafted count will be 400, as there are still four sequences pending to be sent to the leads.


Sent as plain text(Boolean): send_as_plain_text

Type: Boolean
Description: The “Sent as plain text” metric indicates whether the email campaign was sent as plain text or not. When this metric is set to “True,” it means that the campaign was sent as plain text, which implies that open rates and click rates were not tracked for the emails in this campaign. Plain text emails do not include any HTML formatting, images, or tracking elements, making them less visually appealing but often more personal and straightforward in communication.


Campaign track settings(Array): track_settings

Type: Array
Description: The “Campaign track settings” metric is an array that holds the tracking preferences or options for the email campaign. It allows campaign managers or marketers to enable or disable specific tracking features based on their preferences and requirements. The array may contain one or more of the following tracking options:

  1. DONT_EMAIL_OPEN: If this option is included in the array, it indicates that the campaign open tracking is disabled. In other words, the system will not track or record when recipients open the emails from this campaign. Open rates will not be calculated for the emails sent with this tracking setting.

  2. DONT_LINK_CLICK: If this option is present, it means that the campaign click tracking is disabled. The system will not track or record when recipients click on links or CTAs within the emails from this campaign. Click rates will not be calculated for the emails sent with this tracking setting.

  3. DONT_REPLY_TO_AN_EMAIL: If this option is specified in the array, it signifies that the reply tracking is not enabled for the campaign. The system will not track or record the number of replies received in response to the email campaign. Threaded replies in the master inbox will also not be considered as part of this tracking setting.

By including or excluding these tracking options in the “Campaign track settings” array, marketers can tailor the tracking features of the email campaign to align with their specific goals and preferences.


Campaign Lead Stats: campaign_lead_stats

Type: JSON

Description: The “campaign_lead_stats” JSON object contains various statistics and counts related to the leads in the email campaign. It provides insights into the status and progress of leads within the campaign. The object includes the following key-value pairs:

  1. interested (Number): The “interested” metric represents the number of leads who have been marked with a positive sentiment category in the campaign. In this context, any lead that exhibits positive sentiment or interest is categorized as “interested.”

  2. total (Number): The total number of leads in the campaign. This represents the overall count of leads included in the email campaign.

  3. notStarted (Number): The number of leads which are not started. These are the leads for whom the first sequence is yet to be sent. They are in the preparatory phase of the campaign.

  4. inprogress (Number): The number of leads which are in progress. These are the leads for whom the first sequence has been sent, and subsequent sequences will be sent based on the sequence delay. They are actively engaged with the campaign.

  5. completed (Number): The number of leads which are completed. This includes leads for whom the sequence is completed, or the lead has replied. They have reached the end of their email sequence.

  6. blocked (Number): The number of blocked leads. These leads have been blocked and are not eligible to receive further emails in the campaign.

  7. paused (Number): The number of paused leads. These leads were paused and temporarily excluded from receiving emails in the campaign.

  8. unsubscribed_count (Number): The number of unsubscribed leads. These are the leads who have unsubscribed from the campaign and opted out of further email communication.

  9. stopped (Number): The number of stopped leads. Leads get stopped for various reasons, including when a reply is fetched, no email or Social Media profile is found based on the sequence, or the lead is blocked.


Now that these have been defined, we'll need to create our base line "percentage calculator formula/function". This function will be used across the rest of the guide to create these % calculations.

You don't need to create the function the same way, understand the code within it and rebuild it to your best needs.

The formula to calculate the percentage

const findPercentage = ({ part = 0, whole = 0, roundOutput }) => {
    if (part === 0 || whole === 0) return 0;

    const percent = 100 * (part / whole);

    if (Number.isSafeInteger(percent)) {
      /** Check if a number is a whole number */
      return percent;
    }

    if (roundOutput) {
      return Math.round(percent);
    }

    return percent.toFixed(2);
  };

The formula for sent percentage:

sent_percentage = findPercentage({
    part: data.total_count - data.drafted_count,
    whole: data.total_count,
});

Calculating open rate for campaigns with Open Rate tracking turned off / Plain text emails

Open Rate = findPercentage({
    part: unique_open_count,
    whole: unique_sent_count,
})

Calculating click rate for campaigns with Plain text emails

Open Rate = findPercentage({
    part: unique_click_count,
    whole: unique_sent_count,
})

Now lets move onto the Reply Rate Tracking. Reply rate is calculated based on two conditions:

1) If the campaign is sent as plain text or open rate tracking is disabled

Reply Rate = findPercentage({
  part: reply_count,
  whole: unique_sent_count
})

2. Else, use the below formula

Reply Rate = findPercentage({
  part: reply_count,
  whole: unique_open_count
})

And of course our favourite, Positive reply rate:

Positive Reply Rate = findPercentage({
  part: campaign_lead_stats.interested,
  whole: reply_count
})
Did this answer your question?
😞
😐
😁