Open Tracked/Integrations/Mailgun tag for server Google tag manager

Mailgun tag for server Google tag manager

Mailgun also has an HTTP API that a server container tag can call. The same cautions about customer e-mail apply.

3 min read · Updated October 26, 2026

EEvent in the containerTag calls MailgunEE-mail sent
In this guide
Key takeaways
  • Mailgun's messages endpoint takes form fields and basic authentication with your API key.
  • Use the correct region (US or EU) for your domain.
  • Use it for internal and transactional messages. Use a proper e-mail platform for marketing.

This is the Mailgun counterpart of the SendGrid recipe. The pattern is the same: an event arrives, a tag calls an HTTP API. The details differ, so check Mailgun's documentation. See also Slack notifications and server-side tagging as an alternative to Zapier.

What you need

  • A Mailgun account and a verified sending domain.
  • An API key.
  • To know your region: the API host differs for the US and the EU.
Trusted

Brands that grow on cleaner data

Stores and agencies use Open Tracked to see which ads earn the sale.

The request

Mailgun's messages endpoint expects form-encoded fields and basic authentication, with api as the user name and your key as the password.

const sendHttpRequest = require("sendHttpRequest");
const encodeUriComponent = require("encodeUriComponent");
const toBase64 = require("toBase64");

const host = data.region === "eu" ? "api.eu.mailgun.net" : "api.mailgun.net";
const body = "from=" + encodeUriComponent(data.from) +
  "&to=" + encodeUriComponent(data.to) +
  "&subject=" + encodeUriComponent(data.subject) +
  "&text=" + encodeUriComponent(data.text);

sendHttpRequest("https://" + host + "/v3/" + data.domain + "/messages", (statusCode) => {
  statusCode === 200 ? data.gtmOnSuccess() : data.gtmOnFailure();
}, {
  method: "POST",
  headers: {
    "Authorization": "Basic " + toBase64("api:" + data.apiKey),
    "Content-Type": "application/x-www-form-urlencoded"
  },
  timeout: 5000
}, body);

Allow the Mailgun hosts in the template permissions and keep the key in a secure field.

Use it wisely

  • Internal alerts and simple notifications: fine.
  • Customer marketing: use an e-mail platform with consent records and unsubscribe handling.
  • Do not put personal data into messages to third-party addresses without a basis.
Ask AI

Ask Ari instead of digging through reports

Ari reads your tracking and ad data and answers in plain words.

Errors

Symptom401
Likely causeThe key or the user name is wrong.
FixUse api as the user and your key as the password.
SymptomNot found
Likely causeThe domain or region is wrong.
FixCheck the domain name and the EU or US host.
SymptomRejected
Likely causeThe sender domain is not verified.
FixVerify DNS records.
SymptomDuplicates
Likely causeThe trigger fires twice.
FixAdd a condition.
0 of 5 done

A realistic example

A small store wants an internal e-mail whenever an order above a threshold arrives, so the owner sees it on her phone. It adds a tag to its server container that calls Mailgun's messages endpoint on purchase events above the threshold, using its verified EU domain and the EU host. The first test fails with a not-found error, because the tag used the US host. After switching to the EU host the message arrives, and the team adds a condition so only one message per order is sent. The recipe is simple, and the two mistakes it caught, region and duplicates, are the ones that most people make the first time they try it.

Keep it healthy

Log the response status for each send, and look at the failures once a week. Mailgun reports bounces and complaints in its dashboard, so check that your internal alerts are not landing in spam. If a key is rotated, update the secure field the same day.

Data in, clean out

Raw events in. Clean events out.

Open Tracked collects each event on your own domain, removes the noise and sends what is left to Meta, Google Ads, TikTok.

Frequently asked questions

Can a server container send e-mail through Mailgun?

Yes, by calling the messages endpoint from a tag, with basic authentication.

Which Mailgun region should I use?

The one your domain is set up in: US or EU hosts differ.

Is it good for marketing e-mail?

No. Use an e-mail platform with consent records and unsubscribe handling.

How do I keep the key safe?

In a secure server-side field.

What status means success?

Mailgun returns 200 for an accepted message.

Do I need spreadsheets to read my results?

No. Once tracking is live, the Open Tracked analytics shows spend, revenue, ROAS and profit, and you can ask Ari, the built-in AI assistant, questions about your own numbers in plain words. Ari's allowance depends on your analytics plan.

Is Open Tracked different from Open Track or Open Space Track?

No. Open Tracked is the official name of our server-side tracking platform, and the website is opentracked.io. Many people search for it as Open Track, OpenTrack or Open Space Track. All of them lead to the same product: server-side Google Tag Manager hosting, first-party analytics and a CRM pipeline.

Fix your tracking at the source

Open Tracked hosts your server-side Tag Manager, keeps first-party cookies alive and shows what each ad is really worth.

Open Tracked
Written by

The Open Tracked team

We build Open Tracked: server-side tracking hosting, analytics and the tools around them, for stores that spend on ads. Questions about this guide, or an idea for the next one?

Write to us Read the docs

Was this article helpful?

Comments

Loading comments...

Turn better tracking into better marketing performance

Start free