Skip to main content
Mailgun → BigQueryIntegration guide

Connecting Mailgun to BigQuery

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. BigQuery has no attribution model, no deduplication rules and no opinion about your data — which makes it the only destination on this site where every number is exactly as good as the query that produced it. The join between them succeeds or fails on one thing: whether whatever join key you decide on reaches the Mailgun message before the conversion happens, because BigQuery can only match a conversion it can tie back to a click it recognizes.

Free30 minutesNo obligation

Specific to this pair

Mailgun logs in BigQuery: a send inventory joined to orders

Stream Mailgun webhook events into a BigQuery table keyed on message ID, with the raw payload, and add your application's send log with message ID, user ID, trigger reason and code path. Join them, and orders on user ID, to inventory sends and see ordering after each. That's correlation; use randomized holdbacks for effect. Dedupe on Mailgun's event ID.

BigQuery is the natural home for Mailgun data, because it's the one place a message, the reason it was sent and the order that followed can sit side by side. Stream Mailgun's webhook events (delivered, failed, opened, clicked, unsubscribed, complained) into one table keyed on the message ID, and keep the raw payload beside the parsed columns. Check how long Mailgun retains logs on your plan; anything older only exists if you stored it.

The second table is your application's own send log: message ID, user ID, trigger reason and the code path that sent it. That's the record Mailgun can't give you. Joined to the events table on message ID and to orders on user ID, it answers questions the marketing team has never been able to ask: which sends exist, how many go out, and what share of recipients order within a set period afterwards.

Be clear about what that last query measures. Orders after a send is correlation, since customers who get a reorder reminder were already likely to reorder. If you want an effect, hold back a random share of recipients for one send type in code and compare. Webhooks retry, so dedupe on Mailgun's event ID before counting, and report bounce rates per code path so one broken template isn't averaged away.

Mailgun → BigQuery · what breaks

Why this join usually fails — Mailgun → BigQuery

  1. 01

    Whatever join key you decide on 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

    The warehouse quietly disagreeing with every platform

    This is not a bug — it is the point. Your warehouse counts orders; Google counts click-attributed conversions in its window; Meta counts differently again. When the four numbers differ, the warehouse is usually right about revenue and wrong about attribution, and knowing which question you are answering is the whole skill.

  4. 04

    Nothing reconciles afterwards

    BigQuery will not tell you anything is wrong. Verify by querying the table directly against your source system's own totals, and check for duplicate rows on the join key before trusting any aggregate.

Mailgun → BigQuery · the fix

What working looks like — Mailgun → BigQuery

  • Whatever join key you decide on on every message

  • Conversions arriving in BigQuery

    The row lands in a table you own, joinable to every other table you own, with no window and no expiry.

  • Reconciled against the source

Mailgun → BigQuery · architecture

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

    BigQuery needs a click to match

    BigQuery needs a schema and consistent types. The failure mode is not rejection, it is silent divergence: a column that arrives as a string in one load and an integer in the next, or a timestamp in the wrong zone, which produces answers that look plausible and are not.

  3. 3

    The identifier is the bridge

    Whatever join key you decide on, 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

    Nothing deduplicates for you. Streaming inserts are at-least-once, so a retried load can create duplicate rows, and the only protection is a deduplication step you write and actually run.

Mailgun → BigQuery · normal or broken

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

Normal, not a fault

  • Whatever join key you decide on present on the message

  • Sent from your order system

  • Deduplicated correctly

    Nothing deduplicates for you. Streaming inserts are at-least-once, so a retried load can create duplicate rows, and the only protection is a deduplication step you write and actually run.

  • Reconciles with the source

Actually broken

  • Whatever join key you decide on 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

    This is not a bug — it is the point. Your warehouse counts orders; Google counts click-attributed conversions in its window; Meta counts differently again. When the four numbers differ, the warehouse is usually right about revenue and wrong about attribution, and knowing which question you are answering is the whole skill.

  • Nobody has reconciled it

Mailgun → BigQuery · diagnose

Diagnostic order — Mailgun → BigQuery

  1. 01

    Count messages carrying whatever join key you decide on

  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

    Reconcile warehouse order counts against each platform for one closed window

    The gaps localize the problem: a gap against all platforms is a collection issue, a gap against one is that platform's window or matching.

  5. 05

    Read the match rate, not the success message

    BigQuery will not tell you anything is wrong. Verify by querying the table directly against your source system's own totals, and check for duplicate rows on the join key before trusting any aggregate.

Mailgun → BigQuery · prove

How it gets proven — Mailgun → BigQuery

Source of truth

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

  • Whatever join key you decide on confirmed present on a live message.
  • Warehouse order counts and revenue reconciled against the source system for a fully closed window, with duplicates checked on the join key.
  • Orders reconciled against imported conversions, with the send inventory documented.

Mailgun → BigQuery · free audit

What we check in the free audit

  • Count messages carrying whatever join key you decide on
  • Follow one real conversion end to end
  • Inventory every code path that triggers a send
  • Reconcile warehouse order counts against each platform for one closed window
  • 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 → BigQuery · when not to buy

When you don't need this — Mailgun → BigQuery

  • Measure identifier coverage yourself first — pull your last hundred messages and count how many carry whatever join key you decide on.
  • Deliverability monitoring is the right use of Mailgun's data. Attribution belongs at the order.
  • If you have one store and one ad platform, a warehouse is infrastructure you will maintain for a reconciliation you could do in a spreadsheet.

Mailgun → BigQuery · what we deliver

What gets built — Mailgun → BigQuery

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

    Streaming inserts or scheduled batch loads from your order system, with the raw event retained alongside whatever you derive from it.

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

Point Mailgun webhooks at a small endpoint that inserts each event into a BigQuery table, or pull periodically from Mailgun's events API. Store the raw JSON as well as parsed columns, because the payload differs by event type.

Free · 30 min

Get Mailgun and BigQuery joined properly

Free30 minutesNo obligation