Skip to content

Mailgun: Metadata is not available in opened or clicked events #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gertsteyn opened this issue Oct 26, 2017 · 3 comments
Closed

Mailgun: Metadata is not available in opened or clicked events #76

gertsteyn opened this issue Oct 26, 2017 · 3 comments
Assignees

Comments

@gertsteyn
Copy link

Mailgun now strips the X-Mailgun-Variables header from the message-headers field for clicked/opened and possibly other events. (Strangely not for delivered)

There is now a user-variables dictionary that contains the meta data.

@gertsteyn
Copy link
Author

So it seems user-variables is only shown in their log.

The source code comment: "Mailgun merges metadata fields with the other event fields." is still true

BUT "However, it also includes the original message headers which have the metadata separately as X-Mailgun-Variables." is not true for opened and clicked events, for some reason they strip the X-Mailgun-Variables header!

@medmunds
Copy link
Contributor

Mailgun's approach of merging "custom variables" directly into the posted event is really... inconvenient. Among other issues, it means you must avoid choosing custom variable names that could conflict with any current or future Mailgun tracking event properties if you want to access those variables from a webhook.

I'm starting to think the only way for Anymail to (semi-)reliably recover metadata (custom user-variables) from a Mailgun tracking event is to just include all event data that doesn't match a known Mailgun property. It'll be a little fragile -- if/when Mailgun adds new event properties, Anymail will think those are metadata until it's updated. I'll look at making that change.

A useful Mailgun feature request would be for them to include the 'user-variables' event property in the fields posted to tracking webhooks. (user-variables is available through their events API; it's just not posted to the webhooks in un-merged form.)

@medmunds medmunds self-assigned this Oct 26, 2017
@medmunds
Copy link
Contributor

BTW, a workaround in your event hook is to access the raw Mailgun esp_event fields directly. If your metadata field is named "user1", the value will be available in a Mailgun tracking webhook as event.esp_event["user1"].

(This won't be portable if you ever switch ESPs, of course.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants