Skip to main content

Get to Know AMPscript

Learning Objectives

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

  • Define AMPscript.
  • Describe how Marketing Cloud Engagement uses AMPscript.
  • Recognize AMPscript language and syntax.

What Is AMPscript?

In Marketing Cloud Engagement, you may have come across references to AMPscript or you might have experimented with it already. But what is it? AMPscript is Marketing Cloud Engagement's proprietary scripting language for advanced dynamic content in emails, landing pages, SMS, and push messages. While AMPscript uses basic programming concepts, you don’t have to be a coder to understand AMPscript functions and to use it in your emails. Embrace your inner developer and let’s explore this AMPscript together.

AMPscript Functionality

But first, why AMPscript? AMPscript expands Marketing Cloud Engagement functionality to help you create the one-to-one, personalized communications that are so coveted by digital marketers. 

AMPscript is used to:

  • Personalize emails using subscriber or contact data.
  • Create complex, highly dynamic emails using conditional logic.
  • Clean and format data.
  • Add real-time information to emails such as date or time.
  • Track impressions.

And that just scratches the surface of what AMPscript can do. Take a look at the chart to see what else you can do with it. 

Category
What AMPscript Does
API
Create SOAP API interactions
Contacts
Modify Marketing Cloud Engagement contact information in the all-subscribers database
Content
Modify Marketing Cloud Engagement content, such as text and images in email messages
Data Extension
Modify data in data extensions
Date Time
Modify date and time information in Marketing Cloud Engagement
Encryption
Encrypt and decrypt Marketing Cloud Engagement data
HTTP
Get, post, and modify HTTP information in Marketing Cloud Engagement
Math
Perform basic math functions
Microsoft Dynamics CRM
Interact with Microsoft Dynamics CRM data
Salesforce
Interact with Sales and Service Cloud data in Marketing Cloud Engagement
Sites
Interact with CloudPages sites
Social
Interact with Social Forward functionality in Email Studio
String
Modify string information in Marketing Cloud Engagement
Utilities
Return and evaluate types of Marketing Cloud Engagement data

Let’s dive into some scenarios where you can use AMPscript. 

  • Complex marketing (commercial) emails: Send a monthly email to loyalty members that displays their current loyalty level, info about their most recent purchase, and a coupon to buy more of your product. AMPscript can be used to reference personal information from the subscriber’s data extension (DE), from a separate loyalty DE that stores loyalty levels and expiration date, and from a purchases DE. This would be difficult to do without AMPscript.
  • Complex transactional emails: Create an abandoned cart email for customers who left an item in their cart. The email is sent using API and uses AMPscript functions to display items in an abandoned cart. (This can be a bit complicated for a non-developer, but having a basic understanding of AMPscript can help you communicate with a developer).
  • Clean data: AMPscript can be used to ensure your data is client-friendly. For example, make sure your emails aren’t sent with incorrect capitalization of your clients' names (Dear john or Dear JOHN).

The Language of AMPscript

Learning a language can be intimidating. Let’s make AMPscript a bit easier to learn by breaking it down by its components. The basic language elements used in AMPscript are characters, variables, and operators. 

Characters

Let’s start with the ABCs (or AMPs) of AMPscript. But first, what does it stand for? Advanced marketing preferences? Apples, mangoes, and papayas? AMP isn't an acronym, but there are other characters that are important for you to know. Here are some common characters that you see in AMPscript code. 

Characters
Purpose
%%
The starting and ending point for all AMPscript.
%%=
describe what you want here =%%

Indicates the beginning (and ending) of inline AMPscript, which displays the return value of the function referenced. Basically, you identify the info you want to be displayed.
%%[
describe what you want and the steps on how to get what you want]%%

Indicates the beginning (and ending) of an AMPscript code block. An AMPscript block can do a bit more than inline, as it can have multiple steps. It can help declare and set variable values. It can also help process conditional logic.
" "
Used to define a literal item, for example a data extension name, a column name, or a data point.
(m == money and money == good)
Parentheses identify an order of group operations within the code.
(@money)
The @ symbol shows us what we are looking for. In this example, money.
v(@allthemoney)
This refers to the value of a variable found in your data.
Note

Though a personalization string  (%%FirstName%%) uses the characters %%, it is not AMPscript. This common functionality is used to insert subscriber attributes or system data into emails. That being said, personalization strings can be used within AMPscript expressions (or chunks of code).

Variables

Variables serve an important role in AMPscript as they help reference data that is stored in your Marketing Cloud Engagement account. Think back to math class where a variable (typically x) is used to identify a number we don’t know yet.  

For example x+2 = 6. 

A variable in AMPscript is a placeholder for data that you don’t know yet (you can’t really guess a customer’s name) but you want to hold a place for that data for use at the time of send. More on that in the next unit.

Operators

AMPscript also uses comparison criteria to help get to the data you need. 

Comparison Operators
==
Is equal to
!=
Is not equal to
> or >=
Greater than or greater than or equal to
< or <=
Less than or less than or equal to
Join Operators
AND In order for the condition to be true, both expressions must evaluate to true.
OR In order for the condition to be true either of the expressions must evaluate to true.
Conditional Operators 
IF, ELSEIF, ELSE, and ENDIF
These terms are used to define data or narrow down results based on set criteria.

AMPscript opens up the doors to create any number of complex, highly dynamic emails without being constrained by user interface wizards or prebuilt templates. In the next unit, we cover the basic functions and syntax that you need to know to start using AMPscript.

Resources

在 Salesforce 帮助中分享 Trailhead 反馈

我们很想听听您使用 Trailhead 的经验——您现在可以随时从 Salesforce 帮助网站访问新的反馈表单。

了解更多 继续分享反馈