How to track email open rates

10 min read

The code in the blog post has been updated to work with Nylas API V3.

In this blog post we explore how to track email open rates. This technical post focuses on how to implement tracking email open rates for Outlook and Gmail. Let’s dive in!

You can find all the code in this blog on our Nylas Samples repository. We recently discussed how to track email open rates on our LiveStream Coding with Nylas:

What is email open rate?

Let’s understand the concept before looking at ways to track email open rates. Email open rates measure the total number of emails opened vs. the total number of emails received by the user.

For a simplified example, consider ten different users received ten emails, and only five were opened. That represents an email open rate of 50%, so 1 out of every 2 emails received was opened by your recipients. This is how email open tracking works.

Measuring your email open rate is one metric for determining whether you need to invest more time in your email marketing efforts to ensure your message is being reached.

Why do you need to track email open rates?

Email open rates are important metrics to track when communicating with your users to understand if your email is being received and opened by the user. Let’s consider a few use cases for tracking email open rates.

Scenario 1: Sending transactional emails

Let’s first describe a transactional email. A transactional email is where the user has completed an action, such as subscribing to a newsletter, and receives an automated email to confirm their subscription (i.e. double-opt-in). 

This type of email is always in response to a user action. There are many examples, such as double-opt-in for newsletter subscription, order or shipping confirmation, or a password reset request. So anytime your user completes a specific action, the user will receive a transactional email with further details.

In this scenario, understanding the type of email is essential to understand if your users can complete specific actions that they have requested. For example, if a user subscribes to a newsletter, tracking the open rate will be essential to ensure they are subscribing.

Scenario 2: Sending commercial or contextual emails

Let’s describe commercial and/or context emails. These emails are sent out to users and are more company focused and not related to a user request. For example, an email drip campaign is sent out to newly onboarded users at a regular cadence to ensure they get the most out of your product. These emails could include how-to videos, important tips, and use cases for how to use your product.

This type of email is where the company or sender is focused on sharing information that may be useful to the user and could benefit them; however, it is at the sender’s discretion. The user has not necessarily requested to receive the email, so it’s purely informational in nature.

Similar to sending transactional emails, each scenario can benefit from knowing the email open rates. For example, let’s take the scenario where new users are joining a product/service. Understanding the email open rates will help you learn if you’re users benefiting from the drip campaign. You may consider personalizing the drip emails with more relevant content to their use case.

Understanding the different types of emails is helpful when learning and measuring email open rates. We are going to explore how to track email open rates next.

How does email open tracking work?

Let’s go through the steps of how email open tracking works. Consider sending a contextual or commercial email to encourage individuals on our newsletter email list to sign up for your product’s free trial!

View the below diagram showing the different paths an email can take:

  1. Create an Email: The step is to write an email to send to the user. Here you can consider personalizing the email sent to the user using mail merge.
  2. Send an Email: The step is sending the email to the user, which you can do using the Nylas Email API. We covered How to Send Emails with Nylas previously.
  3. User read’s email: Our goal is to send an email for the user to open. Knowing the possible paths is useful for determining the open email rate, which is the ratio of the total emails read versus the total emails received by the user. We are going to look at tracking open email rates shortly.

The email can have three possible outcomes in the above scenario: unread, read, and bounced. It’s important to understand if your email is reaching your users, and email deliverability should be considered first before tracking the open email rate.

Let’s circle back to the happy path in the above diagram (steps 1-3 inclusive). We are going to focus on understanding and measuring Step 3. However, you can complete all three steps using the Nylas Email API. The Nylas Email API allows you to create, send and track email open rates using our email API endpoints.

In this section, we’ve covered how email open tracking works.

How to implement email open rate tracking in your app with Nylas, step-by-step

Let’s consider the scenario where you are tracking open rates for either Gmail or Outlook.

How to track email open rates in Outlook

Step 1. Setup Azure app to authenticate users

To access Outlook accounts, you will need to set up an Azure App to connect an Outlook account. Consider checking out our blog on how to create an Azure App.

Step 2. Setup to retrieve Outlook messages

In previous blog posts, we’ve discussed how to send an email using Nylas and how to read an email using Nylas in depth. Let’s briefly go over how to retrieve a message and important Outlook properties to determine email open rate.

The Nylas Email API for retrieving messages provides the information we can use to learn more about email open rates. Looking at the API specifications for the retrieve messages endpoint, we see the property unread for checking whether a message was read or not.

Let’s use the Nylas Node SDK to retrieve an email using the subject as a query parameter and extract the unread property to print out:

import 'dotenv/config'
import Nylas from 'nylas'

// Configure the Nylas instance with your API Key and Server URL
const NylasConfig = {
  apiKey: process.env.NYLAS_API_KEY,
  apiUri: process.env.NYLAS_API_URI,
};

// Initialize Nylas with the configuration
const nylas = new Nylas(NylasConfig)

async function fetchRecentEmails() {
  try {
    const identifier: string = process.env.GRANT_ID
    const message = await nylas.messages.list({
      identifier,
      queryParams: {
        limit: 5,
        in: ['inbox'],
        subject: 'Important Reminder: Book Your Follow-Up!'
      }
    });

    console.log('Message Read:', message.unread)
  } catch (error) {
    console.error('Error fetching emails:', error)
  }
}


// Call the function to fetch emails
fetchRecentEmails()

In this example, we are looking to track open rates for a specific email sent to all users, so we provided the subject as a query parameter. You can use many parameters to query for a specific email sent to many users; check out the Nylas API docs to learn more.

Step 3. How to track email opens in Outlook

Now, since we can retrieve the message for one user, we can complete this step for all users that we send the email. Let’s go over how to track email opens in Outlook. From an earlier diagram, we are looking about three possible outcomes:

  1. Total users that received the message
  2. Total users that did not receive the message
  3. Of the users that received the message, the total users that opened the message

We can extend the previous example by looping over a list of emails that received the same email and checking whether they opened it:

import 'dotenv/config'
import Nylas from 'nylas'

// Configure the Nylas instance with your API Key and Server URL
const NylasConfig = {
  apiKey: process.env.NYLAS_API_KEY,
  apiUri: process.env.NYLAS_API_URI,
}

// Initialize Nylas with the configuration
const nylas = new Nylas(NylasConfig)
const emails = [
  { 
    grantId: 'INSERT_GRANT_ID_1',
    emailAddress: 'INSERT_EMAIL_ADDRESS_1',
  },
  { 
    grantId: 'INSERT_GRANT_ID_2',
    emailAddress: 'INSERT_EMAIL_ADDRESS_2',
  },
  { 
    grantId: 'INSERT_GRANT_ID_2',
    emailAddress: 'INSERT_EMAIL_ADDRESS_3',
  },
]

async function checkEmailOpenRate(grantId) {
  try {
    const message = await nylas.messages.list({
      identifier: grantId,
      queryParams: {
        limit: 1,
        in: ['inbox'],
        subject: 'Important Reminder: Book Your Follow-Up!'
      }
     })
    
    if(message.length === 0) return 'bounced'
    else return !message[0].unread ? 'read' :  'unread'
   })
  } catch (err) {
    console.error("Error:\n", err)
  }
}
const totalEmailsSent = emails.length
let totalEmailsBounced = 0
let totalEmailsRead = 0

emails.map(({emailAddress, grantId}) => {
  const status = checkEmailOpenRate(grantId)
  if(status === 'bounced') totalEmailsBounced++
  if(status === 'read') totalEmailsRead++
}

console.log(`Email Open Rate: 
  ${totalEmailsRead / (totalEmailsSent - totalEmailsBounced)}
  `
)

How to track email open rates in Gmail

Step 1. Setup Google API Project to authenticate users

To access Gmail accounts you will need to set up a Google API Project to authenticate and connect a Gmail account. Consider checking out our blog on how to setup your Google API Project.

Step 2. Setup to retrieve Gmail messages

Retrieving a message for Gmail is similar to all other communication service providers that you can connect and work with when building with Nylas. We’ve covered this in previous blog posts:

Let’s see how to track email opens in Gmail. We can use the unread property available from the Nylas Email API for retrieving messages to determine if a message has been opened by the user.

Step 3. How to track email opens in Gmail

Now, since we can retrieve the message for one user, we can complete this step for all users that we sent the email. We can extend the code examples of how to read emails using Nylas by iterating over a list of emails that received the same email and checking whether they opened it:

import 'dotenv/config'
import Nylas from 'nylas'

// Configure the Nylas instance with your API Key and Server URL
const NylasConfig = {
  apiKey: process.env.NYLAS_API_KEY,
  apiUri: process.env.NYLAS_API_URI,
}

// Initialize Nylas with the configuration
const nylas = new Nylas(NylasConfig)
const emails = [
  { 
    grantId: 'INSERT_GRANT_ID_1',
    emailAddress: 'INSERT_EMAIL_ADDRESS_1',
  },
  { 
    grantId: 'INSERT_GRANT_ID_2',
    emailAddress: 'INSERT_EMAIL_ADDRESS_2',
  },
  { 
    grantId: 'INSERT_GRANT_ID_2',
    emailAddress: 'INSERT_EMAIL_ADDRESS_3',
  },
]

async function checkEmailOpenRate(grantId) {
  try {
    const message = await nylas.messages.list({
      identifier: grantId,
      queryParams: {
        limit: 1,
        in: ['inbox'],
        subject: 'Important Reminder: Book Your Follow-Up!'
      }
     })
    
    if(message.length === 0) return 'bounced'
    else return !message[0].unread ? 'read' :  'unread'
   })
  } catch (err) {
    console.error("Error:\n", err)
  }
}

const totalEmailsSent = emails.length
let totalEmailsBounced = 0
let totalEmailsRead = 0

emails.map(({emailAddress, grantId}) => {
  const status = checkEmailOpenRate(grantId)
  if(status === 'bounced') totalEmailsBounced++
  if(status === 'read') totalEmailsRead++
}

console.log(`Email Open Rate: 
  ${totalEmailsRead / (totalEmailsSent - totalEmailsBounced)}
  `
)

In this section, we considered how to track email open rates for Gmail using the Nylas Email API.

What are other ways you can track messages?

Using the Nylas API, you can extend message tracking to receive notifications via webhooks, when a message is opened, link is clicked, or thread is replied. Visit our documentation to learn more about message tracking with the Nylas Email API.

Why Nylas

The Nylas Email API contains all the information you need to learn more about whether recipients are engaging with your emails and help you make improvements to your email communication all in one place. Using the Nylas Email API is a single solution to create, send and track open email rates.

Build time

In this blog post, we explored how to track email open rates for Outlook and Gmail using the Nylas Email API. Check out the Nylas Email API documentation to learn more and continue building with Nylas. Sign up here if you need to create a Nylas account for free!

Related resources

How to create and read Google Webhooks using Ruby

Create and read your Google webhooks using Ruby and Sinatra, and publish them using Koyeb. Here’s the full guide.

Build mail merge and email templates using TinyMCE Rich Text Editor

Learn how to build Mail Merge and Email Template functionality in your email workflow using TinyMCE Rich Text Editor.

Send emails using TinyMCE Rich Text Editor

Learn how to improve your email workflow using TinyMCE Rich Text Editor.