Marketers / Marketing Cloud

Advanced AMPscript Use Cases for Salesforce Marketing Cloud

By Oana Munteanu

If you’ve landed on this guide, I am assuming that you already have a basic understanding of AMPscript (Marketing Cloud’s proprietary scripting language), which is predominantly used for content personalization and data manipulation.

AMPscript allows you to extend Marketing Cloud functionality beyond its out-of-the-box capabilities. This means that you can develop code and custom solutions, tailored to your own specific needs and requirements.

My aim is to build on common AMPscript use cases and offer you some new ways to leverage AMPscript that you may not know.

READ MORE: What is AMPscript? How to Personalize Your Marketing Cloud Emails

1. Create Dynamic Personalized Links

Similarly to personalizing content, AMPscript can be used to create dynamic URLs (unique to each recipient) based on one or more variables. Let’s say, you need to send an email out with a Call To Action (CTA) that takes each subscriber to a personalized page based on their location. You can achieve this by using the Concatenate function and a variable for the location information, which is stored in the sendable data extension.

This builds the URL based on the core link, e.g. https://yourcompany.com plus the location variable. The end URL would look something like this: https://yourcompany.com/location=%%v(@location)%

Don’t forget to add the RedirectTo function in the output area inside the HTML to track the click activity.

2. Combine AMPscript, GTL & JSON for Personalization at Scale

When it comes to personalization, everyone wants a piece of it. However, most companies fail because their marketing teams don’t have access to the data they need, or the data model is too complex to leverage in communications and customer journeys.

This solution can be used when you need to trigger highly personalized messages in real-time. Think transaction receipts or service notifications that need to be activated as soon as an event takes place. In this situation, instead of waiting for the data to synchronize and do your segmentation in Marketing Cloud, you can collect all the different data points together into a single JSON payload from your source system, and insert it into Marketing Cloud when the event is triggered.

This solution combines Guided Template Language (GTL) with AMPscript to consume the payload file and pass through the information required within the communication. Simply wrap the GTL tags around the AMPscript block and specify the name of the field with the JSON payload. To extract each individual value from the payload use the TreatAsContent function:

{{.datasource JsonVar type=variable source=@datapoint maxrows=20}} {{.data}} {"target":"@datapoint"} {{/data}} 
/*AMPscript block*/
%%[
SET @variable = TreatAsContent (‘{{data field}}’)
]%%
{{/datasource}}

If you are not familiar with GTL this is a template engine, not a scripting language, based on the Mustache (named after its curly brace syntax that resembles the facial hair) and the Handlebars.js template, which are available across different languages. It can be used in any platform application for personalization.

Although AMPscript is predominantly used for personalization in emails and landing pages, there are many other functions used to manage and manipulate data, such as in the examples below.

3. Data extension functions

This set of functions allows you to interact with data extensions and manage your data as required. One of the most popular ones is the Lookup function, which enables you to find certain fields and values to display in your content from a different data extension than the one you’re sending to – based on a criteria that you specify.

For example, you want to send an email to your customers with more details about their membership offer based on their membership tier:

%%=Lookup('Memberships','Tier','MemberID',@memberid)=%%

Use LookupRows() to retrieve more than one variable in one transaction.

Other functions enable you to insert, update or delete data from data extensions. These are particularly useful with forms and cloud pages when you want to capture new data:

%%=InsertData('Memberships','Tier',@tier,'MemberID',@memberid)=%%

Please remember when using these functions that some of them work only in specific scenarios. For example, InsertData only works in a cloud page or SMS, and InsertDE only works in emails. The same goes for Delete, Update and Upsert.

4. Create/update Salesforce objects

As one of the most powerful functions, this enables you to extend the out-of-the-box functionality of your forms and emails. It accesses and makes changes to data straight in your Salesforce CRM system connected to the Marketing Cloud account.

For example, you can search and retrieve customers’ data straight from Salesforce when a cloud page loads, and pre-populate your forms with the relevant information that you already know about them. This helps to not only improve their experience, but also keeps your data up to date as you give customers the opportunity to change their details if necessary. If no matching information is found, then new data is created straight in Salesforce.

Another great scenario is to capture data from interactive emails in Salesforce. Interactive emails are a cool feature in Marketing Cloud which allows your recipients to input data into a form without leaving the email channel. This helps with form conversions as it makes it easier and quicker for users to submit information.

However, one of the limitations it has is that it only captures the data in a data extension, without pushing it to Salesforce. To overcome this limitation, you can add AMPscript on your cloud page and send the data to CRM also, making it available to more than just your Marketing users.

Final Thoughts

To learn more about how you can use AMPscript to unlock the power of Marketing Cloud, check out these resources (ordered from easy to advanced):

The Author

Oana Munteanu

Oana Munteanu is a Salesforce Marketing Cloud Champion and a Senior Marketing Consultant at Bluewolf, an IBM Company.

Leave a Reply