- Products
- Solutions Use casesBy industry
- Developers
- Resources Connect
- Pricing
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:
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.
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.
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.
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.
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:
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.
Let’s consider the scenario where you are tracking open rates for either Gmail or Outlook.
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.
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.
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:
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)} ` )
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.
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.
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.
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.
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.
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!
Ram loves teaching, building and exploring technologies. He is passionate about empowering developers to ship amazing products to market as fast as possible ????. Ram is excited to share knowledge and help others. He’s a Relaxed Tomato ????.