AMPscript Workshop

As we have previously made an HTML email from scratch, we’re going to build on that email by adding in some AMPscript, first to add in some personalization and then taking that personalization a step further by having it reflect the product that your customer wants to see.

You’ll remember that we start with this generic travel email:

[Download the code….]

 

Personalization Strings

Personalization is extremely important in emails. The numbers are clear that when people get email that is personalized to their name they are more likely to open and engage with it and feel like they have a stronger connection to the company.

Next we want to add in personalization strings to add in the simple things like the user’s first name and urls for the email preference links. Personalization links are used if you’re using subscriber lists, you’ve set up your subscriber attributes for your organization and the personalization in your email is simple and nonrepetitive. If you’re repeating the same strings several times you may as well create a variable, which I will talk about in the next section.

Using personalization strings inline is very simple. You just set up the strings you want to use in the Profile Management of your subscribers. The most common are firstname, lastname, fullname, emailladdr, member_busname, member_address, member_city, replyemailaddreess, xtshortdate, and xtlongdate. But they by no means end there. (Here’s a comprehensive list.)

 

When using them in your code you simply start and end with 2 percentage signs on each side of the string, like so:

<p>Hello %%firstname%%!</p>

Beyond the personalization strings you can add in functions that do things like change the formatting of your string output. For example, say your CRM is filled with inconsistent formatting of people’s names. You can fix this by using an AMPscript function inline:

<p>Hello %%=ProperCase(firstname)=%%!</p>

You see there that we’ve added = signs between our function and string to designate that we’re calling on our ESP to fix how our data outputs. The string itself is now between parentheses. This will deliver your customer’s first name with the first letter capitalized and the rest in lower case. (Here’s a full list of AMPscript functions and syntax for you.)

[ Download the code… ]

 

AMPscript Blocks

If your needs go beyond basic personalizing and into a deeper marketing strategy including shopping preferences, buying habits and search history you’re going to need to engage in some code. If you’re familiar with JavaScript and the like, the formatting and basic functionality will be familiar to you. If you’re not the principals are based in engaging in specific syntax to walk the computer through a basic decision making process until it comes up with the right data to insert into our email.

This email is for a hotel booking company that has been collecting data from user preferences. In this case, the user has been searching for hotels that have different categories of destinations: beach, city, adventure or generic (as a catchall for anyone who doesn’t fit into another category.) We have custom fields in our account that logs the type of travel they’re interested in and that is collected as a column in the report we’re using for the data extensions we’re using to send this email. Our job is to create the script that will choose the right animated image and text to insert into the email.

 

  

 

You can set your block anywhere in your html document or template. Anything in between the %%[ ]%% brackets is considered the block. The code that is outside of the block is considered inline code. The /* */ designate comments. They are ignored by the computer, and are very useful for notes (to yourself or anyone who comes after you) about what happens in those parts of the code.

%%[

/* Hey computer, we got some AMPscript starting for you here */

var @travelType, @firstName, @emailaddr

/* Hey computer, we need some containers for our information: one for our travel type, the image and travel text */

set @travelType = [travelType]
set @firstName = [firstName]
set @emailaddr = [emailaddr]

/* Hey computer, we’re going to need you to make some decisions on which image to post. */
if @travelType == “beach” then set @image=”http://www.krishase.com/images/beach.gif”
elseif @travelType == “city” then set @image=”http://www.krishase.com/images/city.gif”
elseif @travelType == “adventure” then set @image=”http://www.krishase.com/images/adventure.gif”

else set @image = “http://www.krishase.com/images/travel.gif”

endif

]%%

<tr>
<td colspan=”2″><img src=”%%=v(@image)=%%” padding=0 border=0>

[…]

<p>Hello! %%=ProperCase(@firstname)=%%</p>

<p>We noticed you’ve been looking at our awesome %%=v(@travelType)%% destinations. Did you know that if you book your trip in the next 10 days we’ll give you an added bonus of 10% off? That’s right! Book your dream vacation in the next 10 days and we’ll take 10% off the price of your stay.</p>
<p>Ready to go, %%=ProperCase(@firstname)=%%?</p>

[ Download the code… ]

About author

kris

Post a comment