Forum: Ruby on Rails Introducing MailJack: autogenerate querystring parameters that are appended to links in your emails

Afc8915df9cbb5c119ea0057d17fabd2?d=identicon&s=25 PeterP (Guest)
on 2013-06-07 00:49
(Received via mailing list)
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! :)
5b50fec1e5bf39bb4d75b199130882f7?d=identicon&s=25 Josh Jordan (Guest)
on 2013-06-08 10:43
(Received via mailing list)
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.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.