Skip to main content
Mailgun → GA4Integration guide

Connecting Mailgun to GA4

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. GA4 is where the business goes to understand what happened, which makes an unattributed conversion there expensive in decisions rather than in ad spend. The join between them succeeds or fails on one thing: whether the GA4 client_id reaches the Mailgun message before the conversion happens, because GA4 can only match a conversion it can tie back to a click it recognizes.

Free30 minutesNo obligation

Specific to this pair

Mailgun to GA4: tag every link your code sends

Make every code path sending through Mailgun add utm_source, utm_medium=email and a utm_campaign naming the trigger, such as abandoned_cart, since Mailgun's redirect keeps whatever UTMs exist. Keep Mailgun webhooks out of GA4: they lack a client_id and include scanner clicks. Send the order with the session's client_id, and check how many email-credited buyers were already mid-checkout.

Mailgun's click tracking rewrites links through its tracking domain and redirects to your URL, so whatever UTM parameters your code put on the link survive, and if it put none the visit lands in GA4 as (direct) or a webmail referral. The GA4 job is making every code path that sends through Mailgun add utm_source, utm_medium=email and a utm_campaign naming the trigger, such as abandoned_cart or reorder_reminder, so email sessions are visible as email.

Keep Mailgun events out of GA4. A clicked webhook forwarded as a Measurement Protocol event has no client_id and creates phantom users, and link scanners in corporate mail systems follow links no person clicked. The order is the conversion, sent with the client_id of the session that placed it.

The GA4-specific trap is credit shifting between channels. Session-level reports credit the last non-direct source, so a well-tagged transactional email clicked just before purchase takes the session away from the paid click that acquired the customer. That is accurate for the session, but before deciding email drives sales, check how many of those orders came from people who were already mid-checkout when the reminder fired.

Mailgun → GA4 · what breaks

Why this join usually fails — Mailgun → GA4

  1. 01

    The GA4 client_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

    Everything lands under (direct)/(none)

    The classic Measurement Protocol symptom, and it always means the same thing: the client_id was missing or wrong, so GA4 had no session to attach the event to and invented a new user.

  4. 04

    Nothing reconciles afterwards

    GA4 DebugView shows events arriving with their parameters, and Realtime confirms the user and session they attached to. Neither tells you whether you are double-counting — for that, compare GA4's conversion count against the source system's record for the same window.

Mailgun → GA4 · the fix

What working looks like — Mailgun → GA4

  • The GA4 client_id on every message

  • Conversions arriving in GA4

    Conversions appear in GA4 attributed to the original session's source and medium, so acquisition reporting reflects what actually drove revenue.

  • Reconciled against the source

Mailgun → GA4 · architecture

How Mailgun and GA4 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

    GA4 needs a click to match

    GA4 needs the client_id to attach a server event to the user and session that produced the click. Without it there is no attribution to inherit and the event is orphaned.

  3. 3

    The identifier is the bridge

    The GA4 client_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

    GA4 has no built-in deduplication for Measurement Protocol. If the browser also sends the event, it counts twice. The only reliable approach is to decide per event which side sends it, and enforce that decision — GA4 will not protect you from your own duplicates.

Mailgun → GA4 · normal or broken

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

Normal, not a fault

  • The GA4 client_id present on the message

  • Sent from your order system

  • Deduplicated correctly

    GA4 has no built-in deduplication for Measurement Protocol. If the browser also sends the event, it counts twice. The only reliable approach is to decide per event which side sends it, and enforce that decision — GA4 will not protect you from your own duplicates.

  • Reconciles with the source

Actually broken

  • The GA4 client_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 classic Measurement Protocol symptom, and it always means the same thing: the client_id was missing or wrong, so GA4 had no session to attach the event to and invented a new user.

  • Nobody has reconciled it

Mailgun → GA4 · diagnose

Diagnostic order — Mailgun → GA4

  1. 01

    Count messages carrying the GA4 client_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 whether server events carry a session and a source

    In GA4 Realtime or DebugView, find the event and look at its session and traffic source. A brand-new user with no source on every server event is the missing-client_id signature.

  5. 05

    Read the match rate, not the success message

    GA4 DebugView shows events arriving with their parameters, and Realtime confirms the user and session they attached to. Neither tells you whether you are double-counting — for that, compare GA4's conversion count against the source system's record for the same window.

Mailgun → GA4 · prove

How it gets proven — Mailgun → GA4

Source of truth

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

  • The GA4 client_id confirmed present on a live message.
  • Server events confirmed in DebugView attaching to an existing session with the original traffic source intact.
  • Orders reconciled against imported conversions, with the send inventory documented.

Mailgun → GA4 · free audit

What we check in the free audit

  • Count messages carrying the GA4 client_id
  • Follow one real conversion end to end
  • Inventory every code path that triggers a send
  • Check whether server events carry a session and a source
  • 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 → GA4 · when not to buy

When you don't need this — Mailgun → GA4

  • Measure identifier coverage yourself first — pull your last hundred messages and count how many carry the GA4 client_id.
  • Deliverability monitoring is the right use of Mailgun's data. Attribution belongs at the order.
  • GA4 is reporting, not bidding. If your problem is ad platform optimization, fix the ad platform destination first — GA4 will not change what any campaign does.

Mailgun → GA4 · what we deliver

What gets built — Mailgun → GA4

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

    Measurement Protocol events with the client_id, session_id and the correct measurement ID and API secret, sent server-side.

  • 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 → GA4 questions, answered

Add UTM parameters to every link in the templates your code sends; Mailgun's tracked links redirect with them intact. Do not send Mailgun webhook events into GA4 as conversions.

Free · 30 min

Get Mailgun and GA4 joined properly

Free30 minutesNo obligation