Skip to main content
Mailgun → PostHogIntegration guide

Connecting Mailgun to PostHog

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. PostHog can be self-hosted, which changes the calculus entirely: the data stays on infrastructure you control, and so does the responsibility for everything that goes wrong with it. The join between them succeeds or fails on one thing: whether the distinct_id reaches the Mailgun message before the conversion happens, because PostHog can only match a conversion it can tie back to a click it recognizes.

Free30 minutesNo obligation

Specific to this pair

Mailgun events on the PostHog person who received them

Attach your PostHog distinct_id to each Mailgun message as a custom variable, then capture email delivered and email link clicked events from the webhook with the trigger reason and message ID, using UUIDs derived from Mailgun's event ID. Leave opens out, filter email events from active-user definitions, and measure effect as a funnel to a real product action.

PostHog is one of the few destinations where Mailgun's own events belong. A product team wants to know whether the onboarding email brought people back, and that question is answered by putting Mailgun's delivered and clicked events on the same person as their product activity. The join is the distinct_id: attach your PostHog distinct_id to each message as a Mailgun custom variable, so the webhook can send it back.

From your webhook handler, capture events such as email delivered and email link clicked against that distinct_id, with the trigger reason and Mailgun's message ID as properties. Send each with a UUID derived from Mailgun's event ID, because Mailgun retries webhooks it thinks failed, and on a self-hosted instance nothing else will catch the duplicates. If you self-host PostHog, keep the handler on the same infrastructure so recipient data stays in-house.

Leave opens out or mark them as unreliable; Apple Mail prefetching fires them for people who never looked. Be careful with activity metrics too: a server-side email event on a person can make them count as active in insights that use any event. Filter email events out of active-user definitions, and measure the email's effect as a funnel from link clicked to a real product action.

Mailgun → PostHog · what breaks

Why this join usually fails — Mailgun → PostHog

  1. 01

    The distinct_id never reaches Mailgun

    No session, no click, and the trigger conditions are buried in application code rather than in a campaign tool.

  2. 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.

  3. 03

    Self-hosting the analytics and the outage together

    The advantage of owning the pipeline is that nothing blocks it. The cost is that when the ingestion instance fills its disk on a Saturday, the events are gone and nobody is paged. Hosted tools fail differently and more visibly.

  4. 04

    Nothing reconciles afterwards

    PostHog shows events in the activity view within moments. On a self-hosted instance, check the ingestion lag as well — events that are queued are not events that are lost, and the two need different responses.

Mailgun → PostHog · the fix

What working looks like — Mailgun → PostHog

  • The distinct_id on every message

  • Conversions arriving in PostHog

    The event lands on the person profile and becomes available in insights, funnels and session replay.

  • Reconciled against the source

Mailgun → PostHog · architecture

How Mailgun and PostHog actually connect

  1. 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. 2

    PostHog needs a click to match

    PostHog needs a distinct_id, an event name and its properties. Self-hosted instances additionally need the ingestion endpoint reachable and the project API key correct, which is a class of failure hosted tools do not have.

  3. 3

    The identifier is the bridge

    The distinct_id, captured at the visit and carried into the Mailgun message.

  4. 4

    The event source decides reliability

    Send orders. Use Mailgun events for deliverability monitoring only.

  5. 5

    Deduplication at the destination

    PostHog deduplicates on the event UUID where supplied. Without one, a retried batch duplicates, and on a self-hosted instance there is no vendor support desk to notice it for you.

Mailgun → PostHog · normal or broken

Working vs. broken, side by side — Mailgun → PostHog

Normal, not a fault

  • The distinct_id present on the message

  • Sent from your order system

  • Deduplicated correctly

    PostHog deduplicates on the event UUID where supplied. Without one, a retried batch duplicates, and on a self-hosted instance there is no vendor support desk to notice it for you.

  • Reconciles with the source

Actually broken

  • The distinct_id 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

    The advantage of owning the pipeline is that nothing blocks it. The cost is that when the ingestion instance fills its disk on a Saturday, the events are gone and nobody is paged. Hosted tools fail differently and more visibly.

  • Nobody has reconciled it

Mailgun → PostHog · diagnose

Diagnostic order — Mailgun → PostHog

  1. 01

    Count messages carrying the distinct_id

  2. 02

    Follow one real conversion end to end

  3. 03

    Inventory every code path that triggers a send

    Usually the first time anyone has, and it frequently finds sends nobody remembers building.

  4. 04

    Check ingestion health and disk before debugging any missing event

    On self-hosted instances the answer is infrastructure far more often than it is instrumentation.

  5. 05

    Read the match rate, not the success message

    PostHog shows events in the activity view within moments. On a self-hosted instance, check the ingestion lag as well — events that are queued are not events that are lost, and the two need different responses.

Mailgun → PostHog · prove

How it gets proven — Mailgun → PostHog

Source of truth

Your application's own record of what triggered the send, joined to the order.

  • The distinct_id confirmed present on a live message.
  • Purchase events reconciled per transaction against your billing system, with ingestion lag checked over the same window.
  • Orders reconciled against imported conversions, with the send inventory documented.

Mailgun → PostHog · free audit

What we check in the free audit

  • Count messages carrying the distinct_id
  • Follow one real conversion end to end
  • Inventory every code path that triggers a send
  • Check ingestion health and disk before debugging any missing event
  • Read the match rate, not the success message

Checked against

Your application's own record of what triggered the send, joined to the order.

Get my free conversion tracking audit

Free30 minutesNo obligation

Mailgun → PostHog · when not to buy

When you don't need this — Mailgun → PostHog

  • Measure identifier coverage yourself first — pull your last hundred messages and count how many carry the distinct_id.
  • Deliverability monitoring is the right use of Mailgun's data. Attribution belongs at the order.
  • If you have no reason to keep the data on your own infrastructure and no team to run it, the hosted product removes the only real downside of this one.

Mailgun → PostHog · what we deliver

What gets built — Mailgun → PostHog

  • 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 PostHog

    The PostHog capture API, posted server-side from your backend to your own instance or to PostHog Cloud.

  • 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.

Get my free conversion tracking audit

From $400 · See packages

FAQ

Mailgun → PostHog questions, answered

Yes. Attach the user's distinct_id to each message as a custom variable, then capture delivered and clicked events from the Mailgun webhook against that ID.

Free · 30 min

Get Mailgun and PostHog joined properly

Free30 minutesNo obligation