Mar 11, 2009

Dynamically customized transactional emails with MailChimp

farecompare-logoAt Farecompare.com, you can setup fare alerts, like "tell me if airfare for ATL to NYC drops by 20%." Farecompare will check 3 times a day, and then instantly alert you if they detect the changes you’re looking for. They’re the first to offer such a service, and it’s extremely cool.

They use MailChimp’s API and our powerful dynamic merge tags to send these highly customized "transactional" emails.

Here’s what one of their email alerts looks like:

fare-compare-final

Now let’s take a look at how they use MailChimp’s dynamic merge tags to get this done…

The challenging thing about these transactional emails is that each recipient might have up to 5 different "city pair" alerts setup. Here’s an example where I have three alerts for three city pairs:

alert-settings1

I specified three cities I travel to often (in my fantasy land, where I actually have time to travel). Sydney, Portland, and Boston.

I’ve set them up to send me an email alert whenever airfare to any of these cities changes by 20%:

alert-settings

So you might think, "easy enough. just setup the mailchimp database so that each recipient has merge fields, like fname, lname, origcity1, destcity1, price1, origcity2, destcity2, price2, and so on and so forth."

Problem is, if one of the city pairs got updated pricing (let’s say ATL-BOS airfare dropped 25%) but the other city pairs didn’t change, the email would need to ONLY list the ATL-BOS information, and NOT the other two city pairs. Basically, you want some conditional statements that say, "If an update for a city pair exists, include it. Otherwise, leave it blank."

Dynamic content merge tags

Here’s how they do it.

This is what their email looks like in the MailChimp campaign builder:

fare-comparedraft

You’ll notice 5 different "blocks" of content, where a possible city-pair alert would appear.

They’ve coded each of those blocks with our dynamic merge tags like this:

*|IF:ORIG1|*
<table width="358″ border="0″ cellspacing="0″ cellpadding="0″ bgcolor="#ffffff" style="font-family: Arial, Helvetica, sans-serif;font-size: 12px;color: #000000;">
<tr>
<td colspan="2″ height="10″><img src="http://www.farecompare.com/blah.jpg" alt=""></td>
</tr>
<tr>
<td width="197″ valign="top" style="padding-left: 10px; padding-top: 10px">
<strong>Itinerary</strong><br><br>
» From: *|ORIG1|*<br>
» To: *|DEST1|*<br>
</td>
<td width="161″ align="center">
Find fares from<br>
<span style="font-size: 23px; color: #ff9900″><a href="http://www.farecompare.com/blah?key=*|KEY1|*">
<strong>*|PRICE1|*</strong></a></span><br>
*|SAVE1|*<br>

<a href="http://www.farecompare.com/blah?key=*|KEY1|*"><img src="http://www.farecompare.com/blah.jpg" alt="Find Flights" border="0″></a>
</td>
</tr>
<tr>
<td colspan="2″ height="10″><img src="http://www.farecompare.com/blah.jpg" alt=""></td>
</tr>
</table>
<br>
*|END:IF|*

There’s a lot of formatting code in there, so let’s distill it down to the important merge tags:

*|IF:ORIG1|*

From: *|ORIG1|*

To: *|DEST1|*

Find fares from

*|PRICE1|*

*|SAVE1|*

*|END:IF|*


*|IF:ORIG2|*

From: *|ORIG2|*

To: *|DEST2|*

Find fares from

*|PRICE2|*

*|SAVE2|*

*|END:IF|*


*|IF:ORIG3|*

From: *|ORIG3|*

To: *|DEST3|*

Find fares from

*|PRICE3|*

*|SAVE3|*

*|END:IF|*

So for each block, they say IF there is a price update, then insert it along with its price and savings amount.

If there are no updates, the other blocks will not show up.

This conditional logic is exactly what our dynamic merge tags are for. You can also use conditional merge tags in your A/B test campaigns to swap out and A/B test your email’s content and designs (here’s a tutorial on how to do that).

For a complete list of MailChimp merge tags (and what they all do), see our merge tag cheatsheet.

Refresh Database via API

But remember how they send these updates 3 times a day?

That means they have to wipe everything in MailChimp clean 3 times a day, then re-populate the list with new data for each member.

If you’ve ever created a list in MailChimp, you know that’s no easy task.

Unless you’re using the MailChimp API to sync your member info.

3 times a day, Farecompare connects to MailChimp and performs a member update to refresh all their fields and replace them with the most up-to-the-minute airfares.

Turn off click tracking and use Google Analytics

There’s one important thing to note here. This is a really, really smart hack of MailChimp. Since it’s a hack, there are some compromises. For one, click tracking is not going to be very useful to you if you’re constantly wiping out your database through the API and then replacing all your recipient merge fields. There are more hacks to get around that issue, but we strongly recommend you simply turn off all click tracking, and use our Google Analytics integration instead to track your clicks:

google-analytics

In this type of daily transactional campaign, looking at your campaign stats every day in MailChimp is a little unrealistic anyway. You should just log in to Google Analytics to see how your daily alerts are driving traffic to your website and resulting in conversions.

Who’s this for?

If you run an e-commerce site and you send transactional alerts of some sort (price or inventory alerts, for example), and:

  • you want to measure opens, clicks, and conversions,
  • AND the alerts will all follow the same standard template

then setting up this kind of MailChimp campaign is perfect. You will need to have someone on staff who can work with the MailChimp API. Or, you can contact a programmer in the MailChimp Experts directory.