My firm is building out dynamic emails that are driven by preference pages built in Cloud Pages using AMPScript for multiple Marketing Cloud clients, most of whom are integrated with Salesforce as their CRM. When we begin working with Marketing Cloud clients, we’re often stunned that they’re not taking advantage of this powerful customization tool to create targeted and personalized emails that are far more engaging. Simply put, you’re most likely not realizing your return on investment with Marketing Cloud if you’re not deploying solutions that utilize AMPScript.
What Is AMPScript?
AMPScript is a proprietary scripting language native to Salesforce Marketing Cloud that is used to insert personalized and dynamic content into email messages, landing pages, and SMS messages.
There’s no documentation on why it’s called AMPScript… although it may have been something like Automated Marketing Cloud Programming Script. And it’s not to be confused with Adobe’s Marketing Cloud Script, AMP.
What Are Some AMPScript Learning Resources?
- Salesforce’s AMPScript Syntax Guide – documents how to correctly form AMPscript function calls, declare variables and values, and reference AMPscript keywords.
- Salesforce Trailhead AMPScript Unit – This module introduces you to the basics of AMPscript, while also giving you the resources you need to dig deeper.
- AMPScript.com – Jackson Chen is a former ExactTarget and Salesforce eMarketing Cloud employee who write this resource for users to learn AMPScript.
- AMPScript Guide – This comprehensive reference manual provides documentation on every AMPscript function, with supporting code examples for real-world scenarios.
- The Drip – This fantastic blog from Salesforce Ben provides some basic and advanced best practices and code examples.
Is There An AMPScript Editor?
One reason many companies avoid using AMPScript is that, while powerful, there are limited resources to edit and test AMPScript… so it can be quite frustrating. With no native editor in the platform that autocompletes and verifies your syntax for errors, Marketing Cloud users are forced to use third-party solutions or simply write and test, write and test, write and test. I’m not seeing a change to this any time soon, so we’re going to provide some resources and examples here that may be helpful.
- Ampscript.io – this is an online AMPScript editor developed by Zuzanna Jarczynska. This application enables easy AMPscript editing through syntax highlighting and it will warn you about possible syntax errors in your code.
- Microsoft Visual Studio – this Visual Studio Code extension allows you to connect directly to your Marketing Cloud Account, enables syntax highlighting for AMPScript, has built-in documentation for all AMPScript functions, and also adds code snippets for language elements and functions. Each snippet includes a detailed description of the function and its parameters. Snippets also show up when you hover over a function name.
- Sublime Text with Package Control – this AMPScript syntax highlighter can be installed for the popular Sublime Text editor using the installation package.
Here’s a simple example of a personalized message that is built with AMPScript that pulls first and last name from your Marketing Cloud subscriber attributes:
%%[ /* Set variables for personalized content */ SET @firstName = AttributeValue("FirstName") SET @lastName = AttributeValue("LastName") /* Insert personalized content into email message */ Hi @firstName, Thank you for signing up for our newsletter! We hope you find the content valuable. Sincerely, The @lastName Family ]%%
Here’s an example where we can dynamically change the content of the message by looking up the interest attribute of a subscriber
%%[ /* Set variables for dynamic content */ SET @interest = AttributeValue("Interest") /* Display content based on subscriber's interest */ IF @interest == "Sports" THEN Output(Concat("Check out our latest sports news and updates!")) ELSEIF @interest == "Technology" THEN Output(Concat("Stay up-to-date on the latest tech trends and innovations with our newsletter!")) ELSE Output(Concat("Discover a wide range of topics in our newsletter!")) ENDIF ]%%
Or, if you have a comma-separated attribute of interests, you can see if your term is included in the attribute:
%%[ /* Set variables for personalized content */ SET @interestList = AttributeValue("InterestList") SET @term = "Technology" /* Check if term exists in interest list */ IF IndexOf(@interestList, @term) > 0 THEN Output(Concat("You are interested in technology!")) ELSE Output(Concat("Your interests are not related to technology.")) ENDIF ]%%
You can even loop through a data extension to retrieve and display a specific number of records.
%%[ /* Declare variables for personalized content */ var @rows, @row, @rowCount, @numRowsToReturn, @lookupValue, @i /* Set variables for personalized content */ set @lookupValue = "Shirts" set @numRowsToReturn = 3 /* 0 means all, max 2000 */ /* Query and retrieve the rows of data as well as their order */ set @rows = LookupOrderedRows("Orders",@numRowsToReturn,"OrderDate desc, ProductName asc", "ProductType", @lookupValue) set @rowCount = rowcount(@rows) /* Display each of the rows */ if @rowCount > 0 then for @i = 1 to @rowCount do var @ProductName, @OrderDate set @row = row(@rows,@i) /* get row based on counter */ set @ProductName = field(@row,"ProductName") set @OrderDate = field(@row,"OrderDate") ]%% Row %%=v(@i)=%%, %%=v(@ProductName)=%% was ordered on %%=v(@OrderDate)=%% %%[ next @i ]%% %%[ else ]%% No shirt orders found %%[ endif ]%%
And, of course, you can write HTML within the output of your AMPScript to create beautiful, dynamic HTML messages for your subscribers.
If you’re seeking assistance on development of your dynamic HTML email, dynamic SMS messages, or dynamic landing pages built on Cloud Pages, don’t hesitate to reach out to Highbridge for assistance.