- 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 dive deeper into tracking emails in Gmail. Email tracking is important because it allows us to understand how our readers engage with emails. If we better understand what emails are engaging, we can iterate and improve our email communication with existing potential customers. To learn more about email tracking, consider taking a look at what is email tracking. This technical post focuses on how to implement email tracking in Gmail.
Let’s go over the benefits of tracking emails before we take a look at how to track emails in Gmail.
Tracking emails allows for better email communication management with respect to prioritizing responses. When we track email, we can determine whether the email is open and read, allowing us to take the necessary next steps, such as sending a follow-up email.
Learning about recipient engagement and behaviour toward your email communication is valuable to determine the effectiveness of email campaigns. Using this information, you can iterate and improve your messaging going forward and learn how to tailor your message to different audiences better.
Tracking email further streamlines communication with your users. For example, if a user reads an email, it may prompt a different follow-up versus an email that was left unread. In the scenario where an email was read by the user, such as a receipt or transaction, we may not require a follow-up email. If an email was unopened, we may want to prompt the user with a follow-up email.
By learning about your user’s engagement with your email communication in real-time, you can build out certain follow actions relevant to a specific event. Real-time tracking is useful since the email will be relevant to the user as they have just engaged with it, such as opening it, reading it, or clicking on a specific link.
Gmail is ubiquitous as an email platform and is part of millions of businesses day to day workflow. Let’s look at use cases to track emails in Gmail.
We can track emails successfully delivered to the recipient’s email address. Tracking sent emails is important to ensure the message reaches our users. Tracking sent emails is an important part of improving email deliverability.
Another way to track emails in Gmail is by checking whether the recipient has read the message. Knowing whether the email is opened is important when contacting the recipient with a follow-up for further actions.
Ensuring an email is opened is important to know if the recipient has engaged with the email message. Tracking email opens is important to understand whether the recipient accessed the email message. This is also useful for tracking as we can know the exact moment the recipient opens the email.
Another useful item to track is whether the user clicked on any links found within the email message itself. Another indicator of email engagement is the user finding the content useful and continuing to engage by clicking on the call to action found within the email.
Nylas powers your application’s email, calendar, and contacts. Let’s focus on our Nylas Email API for email tracking. We offer different ways of email tracking:
The second approach to track emails does not require a connected account and provides real-time email tracking through the use of Nylas webhooks. We’ve covered how to setup webhooks with NodeJs and how to develop with webhooks locally using the Nylas Node SDK:
To get started with Nylas, consider using the Quickstart Guides to grab the code for sending an email, with environment setup details included. We provide Quickstart Guides in Python, Node, Ruby and Java. We recently covered using the Quickstart Guides on Coding with Nylas:
For the step-by-step guide, we will be using the Node SDK.
In this section, we will look at tracking sent emails in Gmail. Let’s take a look at the code available in the Quickstart Guide to send emails in Gmail:
app.post("/nylas/send-email", async (req, res) => { try { const sentMessage = await nylas.messages.send({ identifier: process.env.USER_GRANT_ID, requestBody: { to: [{ name: req.body.sendTo.name, email: req.body.sentTo.email }], replyTo: [{ name: req.body.replyTo.name, email: req.body.replyTo.email }], subject: req.body.subject, body: req.body.body, }, }); res.json(sentMessage); } catch (error) { console.error("Error sending email:", error); } });
Given the above code, once the email is sent, we will receive a message that we can use to determine if the email was sent successfully. If a message was not received, we could check for error responses received. We can also update the code to handle error messages better:
try { // Add system logging for successfully sent message const message = await nylas.messages.send(/* send data */); return res.json({ message }); } catch(error) { // Add system logging for unsuccessfully sent message return res.json({ message: error }); }
In this section, we explored how to track sent emails in Gmail.
Let’s take a look at ways to track email opens. We’ve covered this in-depth in our blog post on how to track email open rates, where we also discuss checking open rates in Gmail and Outlook! Taking the above code sample from the Quick Start guide for sending emails, let’s modify the .send()
to include tracking options for tracking email opens:
requestBody: { ... trackingOptions: { opens: true, }, },
This section explored how to track email opens in Gmail.
Let’s consider ways to track when a link is clicked. We are going to take the previously shared code sample for sending emails and modify the draft.send()
to include link tracking:
requestBody: { ... trackingOptions: { links: true, }, },
This section explored how to track email links in Gmail.
You can sign up for Nylas for free and start building! Nylas provides different approaches for tracking email engagement through connected accounts and real-time tracking using webhooks. Here are links to additional resources:
Consider building using our Quickstart Guides to accelerate your development and try out Nylas Email API tracking functionality.
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 ????.