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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
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
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! :)
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
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.
This topic is locked and can not be replied to.