Tracking Email replies using Mailgun events

Posted By :Harsh Soni |31st May 2019
Tracking the user clicks on the email and reply to the button by using mailgun events.

Mailgun is the most popular developer friendly Transactional Email service provider. It can track every event of the emails and can send the data to you through its Events API. Because of its developer-friendly nature, you can easily access the data from its various API. 

 

Today, we are going to understand the usage of Events in the process to track the emails sent by you. Email Tracking becomes so easy because of the Mailgun Events API, you can track open, click, delivered, Spam, Failures, etc by this.

 

Mailgun provides three ways to interact with Its Data

 

  1. Webhook (Data directly posted to predefined URL)
  2. Events API 
  3. Log Tables (Can be viewed at your Account Settings)

 

Let's start with tracking the Emails Events

 

1. Tracking Open/View

 

To Enable the Open tracking functionality to add the "o:tracking-opens" or "o:tracking" parameters while sending an email from your code. You can also do it by enabling the tracking setting from your Mailgun account. You will need to add CNAME record to your DNS as Specified in the DNS and Domain Verification settings. Below is the sample response of the Open Event

 

{
  "event": "opened",
  "id": "-laxIqj9QWubsjY_3pTq_g",
  "timestamp": 1377047343.042277,
  "log-level": "info",
  "recipient": "[email protected]",
  "geolocation": {
    "country": "US",
    "region": "Texas",
    "city": "Austin"
  },
  "tags": [],
  "campaigns": [],
  "user-variables": {},
  "ip": "111.111.111.111",
  "client-info": {
    "client-type": "mobile browser",
    "client-os": "iOS",
    "device-type": "mobile",
    "client-name": "Mobile Safari",
    "user-agent": "Mozilla/5.0 (iPhone; CPU iPhone OS 6_1 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B143"
  },
  "message": {
    "headers": {
      "message-id": "[email protected]"
    }
  },
}

 

You can also specify your webhook URL so that, when a user open an email, your webhook will be called and you will get the response instantly.

 

2. Tracking Clicks

 

Similar to the open tracking you can also track the click on anything in the mail. You can track the click on the link, image or any element of the message body. You would need to add the "o:tracking-clicks" or "o:tracking" parameters while sending an email from your code. In this case, the links will be overwritten and pointed to Mailgun servers so that they can track click events. You can also mention that you only want links rewritten in the HTML part of a message with the parameter o:tracking-clicks and passing htmlonly. Below is the sample response of the Click Event

 

{
  "event": "clicked",
  "id": "G5zMz2ysS6OxZ2C8xb2Tqg",
  "timestamp": 1377075564.094891,
  "log-level": "info",
  "recipient": "[email protected]",
  "geolocation": {
    "country": "US",
    "region": "TX",
    "city": "Austin"
  },
  "tags": [],
  "url": "http://example.com/signup",
  "ip": "123.123.123.321",
  "campaigns": [],
  "user-variables": {},
  "client-info": {
    "client-type": "browser",
    "client-os": "Linux",
    "device-type": "desktop",
    "client-name": "Chromium",
    "user-agent": "Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/28.0.1500.71 Chrome/28.0.1500.71 Safari/537.36"
  },
  "message": {
    "headers": {
      "message-id": "[email protected]"
    }
  },
} 

 


About Author

Harsh Soni

Harsh is an experienced software developer with a specialization in the MEAN stack. He is skilled in a wide range of web technologies, including Angular, Node.js, PHP, AWS, and Docker.Throughout his career, Harsh has demonstrated a strong commitment to delivering high-quality software solutions that meet the unique needs of his clients and organizations. His proficiency in Angular and Node.js has allowed him to build dynamic and interactive user interfaces, leveraging the power of modern front-end frameworks. Harsh's expertise also extends to cloud computing and infrastructure management using AWS, enabling him to design and deploy scalable applications with ease. Additionally, his knowledge of Docker has enabled him to streamline the development and deployment process, enhancing efficiency and reducing time-to-market. He excels at analyzing complex technical challenges and devising efficient strategies to overcome them, ensuring the successful completion of projects within deadlines.

Request For Proposal

[contact-form-7 404 "Not Found"]

Ready to innovate ? Let's get in touch

Chat With Us