Connecting Mailgun to Segment
Mailgun is developer-facing email infrastructure, which means the sending logic lives in your application and the marketing team frequently does not know what is being sent or when. Segment is a customer data platform rather than an ad network, so sending to it is not about matching a conversion — it is about putting one clean event where every other destination can read it. The join between them succeeds or fails on one thing: whether the userId and anonymousId reaches the Mailgun message before the conversion happens, because Segment can only match a conversion it can tie back to a click it recognizes.
Free30 minutesNo obligation
Specific to this pair
Mailgun into Segment: email events that stay out of ad tools
Map Mailgun webhooks to Segment's email spec events, such as Email Delivered, Email Link Clicked and Email Bounced, via a catalog source or the HTTP API. Attach the Segment userId as a custom variable, add send reason and template, and derive messageId from Mailgun's event ID. Filter these away from ad destinations, and pass unsubscribes as consent traits.
Segment is the one destination in this list where Mailgun events have an obvious slot: its email spec defines events such as Email Delivered, Email Link Clicked and Email Bounced, and downstream tools that follow the spec know what to do with them. Check whether Segment's source catalog currently includes Mailgun; if not, a webhook endpoint that calls Segment's HTTP API does the job.
Identity is the key decision. Attach the Segment userId to each message as a Mailgun custom variable and send it back with every event; matching on recipient email creates a second identity whenever the address differs from the one on file. Add send reason and template as properties, and derive the messageId from Mailgun's event ID so a retried webhook is dropped once instead of reaching every destination twice.
Then decide where these events go. The warehouse and product analytics should get them; ad platform destinations should not, because an email delivery or click isn't a conversion and some mappings will send it as one. Set destination filters before enabling the source. Unsubscribes and complaints are also consent signals, so pass them as traits wherever a downstream marketing tool must respect them.
Mailgun → Segment · what breaks
Why this join usually fails — Mailgun → Segment
- 01
The userId and anonymousId never reaches Mailgun
No session, no click, and the trigger conditions are buried in application code rather than in a campaign tool.
- 02
Nobody able to say why a message was sent
When send logic lives in application code, the marketing team cannot audit it and the engineering team is not thinking about attribution. Messages accumulate, nobody owns the list, and any analysis of email's contribution is unreliable.
- 03
One bad event multiplied across every destination
Segment's value is fan-out, which is also its risk. An inconsistent identity or a duplicated event does not break one report — it breaks every connected tool simultaneously, and tracing it back is harder than debugging a direct integration.
- 04
Nothing reconciles afterwards
Segment's debugger shows events arriving and which destinations accepted them. Arriving is not the test — check a destination you care about and confirm the event landed there with the identity intact, then reconcile against your own records.
Mailgun → Segment · the fix
What working looks like — Mailgun → Segment
The userId and anonymousId on every message
Conversions arriving in Segment
Events land in Segment and forward to every connected destination, warehouse included, on one shared definition.
Reconciled against the source
Mailgun → Segment · architecture
How Mailgun and Segment actually connect
- 1
Mailgun holds the truth
Because sends are triggered in code, the only reliable description of why a message went out lives in your application, not in Mailgun's logs.
- 2
Segment needs a click to match
Segment needs a consistent identity model — the same userId everywhere, an alias when an anonymous visitor becomes known, and event names that follow one spec. Feeding it inconsistent identities pushes the mess to every connected destination at once.
- 3
The identifier is the bridge
The userId and anonymousId, captured at the visit and carried into the Mailgun message.
- 4
The event source decides reliability
Send orders. Use Mailgun events for deliverability monitoring only.
- 5
Deduplication at the destination
Segment deduplicates on messageId within a window. Because it fans out to many destinations, a duplicate here becomes a duplicate everywhere, which makes idempotent messageIds more important than in any single-destination integration.
Mailgun → Segment · normal or broken
Working vs. broken, side by side — Mailgun → Segment
Normal, not a fault
The userId and anonymousId present on the message
Sent from your order system
Deduplicated correctly
Segment deduplicates on messageId within a window. Because it fans out to many destinations, a duplicate here becomes a duplicate everywhere, which makes idempotent messageIds more important than in any single-destination integration.
Reconciles with the source
Actually broken
The userId and anonymousId missing on most records
No session, no click, and the trigger conditions are buried in application code rather than in a campaign tool.
Sent from the browser
When send logic lives in application code, the marketing team cannot audit it and the engineering team is not thinking about attribution. Messages accumulate, nobody owns the list, and any analysis of email's contribution is unreliable.
Counted twice, or not at all
Segment's value is fan-out, which is also its risk. An inconsistent identity or a duplicated event does not break one report — it breaks every connected tool simultaneously, and tracing it back is harder than debugging a direct integration.
Nobody has reconciled it
Mailgun → Segment · diagnose
Diagnostic order — Mailgun → Segment
- 01
Count messages carrying the userId and anonymousId
- 02
Follow one real conversion end to end
- 03
Inventory every code path that triggers a send
Usually the first time anyone has, and it frequently finds sends nobody remembers building.
- 04
Check identity resolution before checking anything downstream
If anonymousId is never aliased to userId, every destination sees two people where there is one, and no downstream fix helps.
- 05
Read the match rate, not the success message
Segment's debugger shows events arriving and which destinations accepted them. Arriving is not the test — check a destination you care about and confirm the event landed there with the identity intact, then reconcile against your own records.
Mailgun → Segment · prove
How it gets proven — Mailgun → Segment
Source of truth
Your application's own record of what triggered the send, joined to the order.
- The userId and anonymousId confirmed present on a live message.
- An anonymous session confirmed aliased to a known user, with the event visible in at least one downstream destination.
- Orders reconciled against imported conversions, with the send inventory documented.
Mailgun → Segment · free audit
What we check in the free audit
- Count messages carrying the userId and anonymousId
- Follow one real conversion end to end
- Inventory every code path that triggers a send
- Check identity resolution before checking anything downstream
- Read the match rate, not the success message
Checked against
Your application's own record of what triggered the send, joined to the order.
Free30 minutesNo obligation
Mailgun → Segment · when not to buy
When you don't need this — Mailgun → Segment
- Measure identifier coverage yourself first — pull your last hundred messages and count how many carry the userId and anonymousId.
- Deliverability monitoring is the right use of Mailgun's data. Attribution belongs at the order.
- If you send to one or two destinations, Segment is infrastructure you do not need — direct integrations are simpler and cheaper. It earns its place at genuine fan-out.
Mailgun → Segment · what we deliver
What gets built — Mailgun → Segment
Identifier capture into Mailgun
Record the trigger reason on the message in your own system and attribute at the order.
Event source: your order system
Send orders. Use Mailgun events for deliverability monitoring only.
Dispatch to Segment
Server-side track and identify calls with a stable messageId, consistent userId, and the click identifier carried as a trait or property.
Reversals where they exist
Refunds reverse at the order.
Written guarantee
95%+ tracking accuracy
Measured against Your application's own record of what triggered the send, joined to the order.. Miss it and we keep working at no cost.
From $400 · See packages
FAQ
Mailgun → Segment questions, answered
Check the current Segment source catalog. If it isn't listed, receive Mailgun webhooks on your own endpoint and send them to Segment's HTTP tracking API with the userId attached to the message.
No. Filter them to the warehouse and analytics tools. An email click mapped to an ad platform event can be counted as a conversion it isn't.
Almost always because the userId and anonymousId never reached the Mailgun message. No session, no click, and the trigger conditions are buried in application code rather than in a campaign tool. Measure coverage before debugging the dispatch.
Segment identifies people by anonymousId before they are known and userId afterwards, and the alias between them is what stitches a session to a customer. Click identifiers travel as event properties or traits rather than as a matching key — Segment does not match anything itself, it forwards. That distinction changes the whole design: get the identity resolution right and every downstream destination inherits it.
Your order system. Send orders. Use Mailgun events for deliverability monitoring only.
Segment's debugger shows events arriving and which destinations accepted them. Arriving is not the test — check a destination you care about and confirm the event landed there with the identity intact, then reconcile against your own records.
More on Mailgun → Segment
- Stripe → SegmentConnecting Stripe to Segment
- PayPal → SegmentConnecting PayPal to Segment
- Shopify → SegmentConnecting Shopify to Segment
RELATED GUIDES
Where Mailgun → Segment fits in the rest of your tracking
- Postmark → SegmentConnecting Postmark to Segment
- Resend → SegmentConnecting Resend to Segment
- SendGrid → SegmentConnecting SendGrid to Segment
- Mailgun → BigQueryConnecting Mailgun to BigQuery
- SaaSConversion tracking for SaaS, from signup through to the payment that matters
- Resend → SnowflakeConnecting Resend to Snowflake
- Postmark → BigQueryConnecting Postmark to BigQuery
- SendGrid → BigQueryConnecting SendGrid to BigQuery
Free · 30 min
Get Mailgun and Segment joined properly
Free30 minutesNo obligation
