markhuge / grunt-mailgun

MIT License
8 stars 8 forks source link

Feature request: campaign tracking #17

Open tleyden opened 6 years ago

tleyden commented 6 years ago

From http://blog.mailgun.com/mailgun-campaign-analytics-taking-analytics-beyond/:

curl https://api.mailgun.net/v2/mailgun.net/messages  
 -F from='Developers ' 
 -F to='Bob Doe ' 
 -F subject='Please consider upgrading' 
 -F text='You will actually save money by upgrading' 
 -F o:campaign='upgrade_reminder' 

With the o:campaign field, it will associate the email with a campaign for analytics purposes.

tleyden commented 6 years ago

Looks like campaigns have been deprecated in favor of tagging

tleyden commented 6 years ago

Looks like this code would need to set the o:tag field, and that would need to be exposed to https://github.com/markhuge/mailgun-stream/, and then to this library.

tleyden commented 6 years ago

If you could provide any more hints at implementing, I could try to put together a PR

markhuge commented 6 years ago

@tleyden hey, sorry just saw this. Will review this after work today

tleyden commented 6 years ago

Cool. I ended up just hacking my local version to add the tags I needed, but it's not a sustainable solution so it would be great to parameterize it.

In grunt-email-workflow/node_modules/mailgun-send/index.js:

{
  parse(data) {
      .... snip ..

    // detect content type
    // TODO this should be its own method
    var isHTML = function(str) { return /<[a-z][\s\S]*>/i.test(str); };
    if (isHTML(body)) data.html = body;
    else data.text = body;

    data.subject = data.subject || this.subject;

    data["o:tag"] = "MyTag"   // <-- Temp hack

    return data;
  }
}