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
code review it.

MailJack - its like LoJack but for the links in your emails. The
this solves is the ability to track click throughs in emails.

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
a Proc to each query string parameter that is evaluated at mail send
Here’s what the configuration looks like

MailJack.config do |config|
config.mailers = [:user_notifier]
config.href_filter = /#{}/
config.encode_to = :utm_source
config.trackable do |track|
track.campaign = lambda{|mailer| mailer.action_name}
track.campaign_group = lambda{|mailer|}

So, mailers are your mailer classes that you want to track in
notation. Href_filter is a regex that will be used to match hrefs in
body of your email. This is useful so you don’t append parameters to
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

In the trackable block, you can specify any number of parameters that
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


Actually, since we have the encode_to parameter specified, it would
actually appear as:


Ok, I hope this is useful to others, as its definitely useful to me!
yes, feedback/code review is very much appreciated! :slight_smile:

Hi Peter. Pretty cool. I think the biggest thing you can do to improve
code here would be to write some tests for it, so you can give your
confidence that it won’t break with each subsequent release.

It would also be beneficial to include the word “Rails” in the
so that people searching for something like this in the context of rails
have an easier time finding it.