I’ve been playing around with Mailgun’s API and got it working. But I’m stuck on one thing. How do I track when a specific email is opened for the first time?
Right now, Mailgun is recording every single time an email is opened. But that’s not what I want. I need to know if a particular email was opened at all, not how many times.
What’s the best way to do this with webhooks? Should I use the data Mailgun provides to identify each email? Or is it better to add custom variables when I send the emails?
I’m using PHP, if that matters. Any tips would be super helpful!
I’ve been in your shoes before, and I can tell you that tracking individual email opens with Mailgun can be tricky. From my experience, the best approach is to use custom variables when sending your emails. Here’s what I did:
When sending each email, I added a unique identifier as a custom variable. Then, I set up a webhook to listen for the ‘opened’ event. In the webhook, I checked if it was the first open for that unique identifier.
To implement this, you’ll need to store the ‘first open’ status somewhere - I used a database. When the webhook receives an ‘opened’ event, it checks the database. If it’s the first open for that email, it records it and triggers whatever action you need.
This method worked well for me, giving accurate first-open data without the noise of multiple opens. It does require a bit more setup, but it’s worth it for the precision. Hope this helps!
hey there, i reccomend using custom vars and a webhook. add a unique id to each email and check for its first open in your system. might store that in a db. hope it helps!