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. Maybe you've even experimented with it. But what is it? AMPscript is the proprietary scripting language for advanced dynamic content in emails, landing pages, SMS, and push messages that you send from Marketing Cloud Engagement. AMPscript uses basic programming concepts, so you don’t have to be a coder to understand AMPscript functions and use them in your messages. 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 digital marketers strive for.
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, such as date or time, to your messages.
- Track impressions.
And that just scratches the surface of what AMPscript can do. This chart shows some of the other things you can do with AMPscript.
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 shows their current loyalty level, info about their most recent purchase, and a coupon to buy more of your product. Use AMPscript 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 DE that contains purchase history. This personalization is difficult to do without AMPscript.
- Complex transactional emails: Create an abandoned cart email for customers who left an item in their cart. Send the email by using the API, and include AMPscript functions to display the items in the cart. This type of message can be a bit complicated for a non-developer, but having a basic understanding of AMPscript can help you communicate with your developers.
- Clean data: AMPscript can be used to ensure your data is customer-friendly. For example, make sure that your emails include the correct capitalization of each recipient's name ("Dear John" instead of "Dear JOHN").
The Language of AMPscript
Learning a language can be intimidating. Let’s make AMPscript a bit easier to learn by breaking down 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. You identify the information you want to appear in the message. |
%%[ 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, such as a data extension name, a column name, or a data point. |
(m == money and money == good) | Group operations within the code. |
(@money) | A reference to a variable. |
v(@allthemoney) | The value of a variable. |
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, but you want to hold a place for that data and populate it when the message is sent. 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 |
!= | Isn't equal to |
> or >= | Greater than or greater than or equal to |
< or <= | Less than or less than or equal to |
Join Operators | |
|---|---|
AND | The condition is true only if both expressions evaluate to true. |
OR | The condition is true if either of the expressions 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 Developers: Getting Started with AMPscript
- Trailblazer Community: Introduction to AMPscript (Login required)
- Salesforce Help: Personalization Strings in Email Studio
- Salesforce Developers: Personalization Strings and AMPscript
