PeterP
2013-Jun-06 22:48 UTC
Introducing MailJack: autogenerate querystring parameters that are appended to links in your emails
Hey All, I just wrote a nifty gem and wanted to share(its one of my first). Wondering if anyone would be so kind as to tell me what they think and/or code review it. MailJack - its like LoJack but for the links in your emails. The problem this solves is the ability to track click throughs in emails. https://github.com/synth/mail_jack Basically, you specify what mailers you want to track links in, and what query string parameters you want to include. What''s cool is that you pass a Proc to each query string parameter that is evaluated at mail send time. Here''s what the configuration looks like MailJack.config do |config| config.mailers = [:user_notifier] config.href_filter = /#{MyApp::Application.config.host}/ config.encode_to = :utm_source config.trackable do |track| track.campaign = lambda{|mailer| mailer.action_name} track.campaign_group = lambda{|mailer| mailer.class.name} end end So, *mailers* are your mailer classes that you want to track in underscore notation. *Href_filter* is a regex that will be used to match hrefs in the body of your email. This is useful so you don''t append parameters to links that go off your domain. *Encode_to* is optional and lets you specify a parameter where MailJack will stash a base64 encoded string of your parameters. In the trackable block, you can specify any number of parameters that you want to appear in the appended query string. So here''s an example. For the following mailer: UserNotifier#welcome_email, all links in that email will have the following appended ?campaign=welcome_email&campaign_group=UserNotifier Actually, since we have the encode_to parameter specified, it would actually appear as: ?utm_source=Y2FtcGFpZ249d2VsY29tZV9lbWFpbCZjYW1wYWlnbl9ncm91cD1Vc2VyTm90aWZpZXI Ok, I hope this is useful to others, as its definitely useful to me! And yes, feedback/code review is very much appreciated! :) -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/23fbeb20-bca0-464b-8dbe-465bad654093%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Josh Jordan
2013-Jun-07 15:43 UTC
Re: Introducing MailJack: autogenerate querystring parameters that are appended to links in your emails
Hi Peter. Pretty cool. I think the biggest thing you can do to improve the code here would be to write some tests for it, so you can give your users confidence that it won''t break with each subsequent release. It would also be beneficial to include the word "Rails" in the description so that people searching for something like this in the context of rails have an easier time finding it. On Thursday, June 6, 2013 6:48:21 PM UTC-4, PeterP wrote:> > Hey All, > > I just wrote a nifty gem and wanted to share(its one of my first). > Wondering if anyone would be so kind as to tell me what they think and/or > code review it. > > MailJack - its like LoJack but for the links in your emails. The problem > this solves is the ability to track click throughs in emails. > > https://github.com/synth/mail_jack > > Basically, you specify what mailers you want to track links in, and what > query string parameters you want to include. What''s cool is that you pass > a Proc to each query string parameter that is evaluated at mail send time. > Here''s what the configuration looks like > > MailJack.config do |config| > config.mailers = [:user_notifier] > config.href_filter = /#{MyApp::Application.config.host}/ > config.encode_to = :utm_source > config.trackable do |track| > track.campaign = lambda{|mailer| mailer.action_name} > track.campaign_group = lambda{|mailer| mailer.class.name} > end > end > > > > > So, *mailers* are your mailer classes that you want to track in > underscore notation. *Href_filter* is a regex that will be used to match > hrefs in the body of your email. This is useful so you don''t append > parameters to links that go off your domain. *Encode_to* is optional and > lets you specify a parameter where MailJack will stash a base64 encoded > string of your parameters. > > In the trackable block, you can specify any number of parameters that you > want to appear in the appended query string. > > So here''s an example. For the following mailer: > UserNotifier#welcome_email, all links in that email will have the following > appended > > ?campaign=welcome_email&campaign_group=UserNotifier > > > Actually, since we have the encode_to parameter specified, it would > actually appear as: > > > ?utm_source=Y2FtcGFpZ249d2VsY29tZV9lbWFpbCZjYW1wYWlnbl9ncm91cD1Vc2VyTm90aWZpZXI> > > Ok, I hope this is useful to others, as its definitely useful to me! And > yes, feedback/code review is very much appreciated! :) > > > > > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/da40bc3a-cf31-4992-8622-f05018473b79%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.