Skip to main content

Personalize a Birthday Email

Learning Objectives

After completing this unit, you’ll be able to:

  • Identify string functions.
  • Set variables in an email.

Basics Covered

Now that you have a refresher on AMPscript basics, let's move on to a few more concepts that can help you solve common AMPscript use cases.  Let's start with strings. 

What Are Strings?

/* No, not silly string.*/ Functions can refer to values in a data extension, or they can use other constant values and even strings. A string is a set of one or more letters, numbers, spaces, or special characters surrounded by a delimiter, in this case a double (") or single (') quote. 

Here are a few examples that work:

'String text goes here'

"String text goes here"

"My string's inside quotes!"

And one example that doesn’t:

'Check out the world's best module!' 

This confuses the system and it would just read 'Check out the world' because the possessive quote is read as a delimiting quote. 

Note

Alternative quote characters, such as smart quotes, are not permitted with AMPscript.

Use String Functions

You may come across situations where you need to manipulate string values to achieve different things. We can do this by using the following functions. Click on the name of each function to see how to use it and example code.


AMPscript often requires the use of multiple string functions, so it’s helpful to know how these work separately before combining them.

Solve Marketing Challenges with AMPscript

Now that you’ve reviewed the basic syntax, some common functions, and even string functions, we want to get you up and running with some practical use cases. Over the next few units, we follow our favorite outdoor gear and apparel retailer Northern Trail Outfitters (NTO) as its technical marketer, Michele Hansley, solves some common email challenges using AMPscript to personalize emails. Each use case gets progressively more complex and uses a variety of AMPscript skills. 

Solution Description

1: Personalize a birthday email.

NTO’s birthday email needs to be updated to include a static promotion, expiration date, and subscriber details based on information found in NTO’s main customer data extension. In addition, Michele needs to make sure the customer’s information is properly formatted and “NTO Rockstar” is displayed if a customer’s name is not available. 

2: Create a loyalty email.

NTO marketing manager, Isabelle Givens, wants to create a status email that shows a subscriber’s current award points and how close they are to reaching a new reward.

3: Create a premium reward email. 

Isabelle also wants to provide a special coupon for premium customers to encourage more sales. The graphics team has created a special banner with a promo code to share with premium customers. The rest of the email remains the same. 

4: Create a data-driven email. 

Isabelle wants to create a new monthly email campaign for loyalty members that promotes new products based on the subscriber’s interests.

Solution 1: Personalize a Birthday Email

Let’s start with Michele’s first task. As mentioned, NTO’s birthday email needs to be updated. Here are the content and requirements Michele has been given.

Email Content:

Happy Birthday, FIRST NAME!

To celebrate your birthday on BIRTHDATE, we are giving you 25% OFF your next order.

Hurry! This offer expires on EXPIRATION DATE. Use Promo Code: BDAY22 when you check out. 

Requirements:

  • Display NTO Rockstar if a customer’s first name is null.
  • Show the expiration date of 12/31/2022.
  • Use the Empty function to achieve this task.
  • Use variables from the NTO Customer data extension with field names:
    • First-Name
    • DOB

Here’s how Michele sets up the solution.

Set Variables

A core concept of AMPscript is declaring and setting variables. While we covered this in the prework, here’s a quick overview of Michele’s steps.

  1. Michele creates her code block and declares the variables.
  2. She adds in the variables from the data extension using: SET @firstName = [First-Name] and SET @birthDate = [DOB]
  3. Once done, she sets the constant variables not included in a data extension. SET @promoAmt = 30

Add Conditions

Next up, Michele needs to add in code to establish “NTO Rockstar” as a greeting, if a person’s first name is unavailable.

  1. Using a conditional IF statement, Michele sets the name to be NTO Rockstar if a customer’s first name is null. IF Empty (@firstName) THEN SET @firstName = "NTO Rockstar" ENDIF

Add Formatting

Finally, to ensure good, clean data, Michele wants to add formatting so both the customer’s first name and date of birth appear correctly in the email. 

  1. Michele uses the Proper Case function for the customer’s first name. %%=ProperCase(@firstName)=%%
  2. For the customer’s birthday, she adds in a date formatting function to ensure the birthday appears as Month Day. %%=FormatDate(@birthDate, "MMM DD")=%%

Example Code

%%[
/* Get data from sending DE and set as variables */
VAR @firstName, @birthDate
SET @firstName = [First-Name]
IF Empty(@firstName) THEN SET @firstName = "NTO Rockstar" ENDIF
SET @birthDate = [DOB]
/* SET promotional variables */SET @promoAmt = 30SET @expDate = "12/31/2022"]%%
Happy Birthday, %%=ProperCase(@firstName)=%%!
To celebrate your birthday on %%=FormatDate(@birthDate, "MMM DD")=%%, we are giving you %%=v(@promoAmt)=%% percent OFF your next order.
Hurry! This offer expires on %%=v(@expDate)=%%.

AMPscript is pretty flexible, so there are many ways to do the same thing. Can you think of other ways to code this email? We can’t wait to see what you come up with.

Next Up: Create a Loyalty Email

Feeling accomplished? Great! Now you are ready to focus on the next solution: creating a loyalty email. 

Resources

Keep learning for
free!
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities