Introduction

Salesforce Marketing Cloud offers various features that enable marketers to create personalised and engaging email campaigns. One of the most powerful features is Data Extensions, which are database tables that store subscriber data. By combining Data Extensions with AMPscript, you can create highly personalised and dynamic content. In this tutorial, we will cover the following topics:

  1. Overview of data extensions in Salesforce Marketing Cloud
  2. Querying data extensions using AMPscript functions (LookupRows, LookupOrderedRows, Lookup)
  3. Adding and updating data in data extensions (InsertData, UpdateData, UpsertData)
  4. Personalising email content based on data extension values
  5. Overview of Data Extensions in Salesforce Marketing Cloud

Overview of data extensions in Salesforce Marketing Cloud

Data Extensions in Salesforce Marketing Cloud are similar to database tables, designed to store and manage structured data. They can be used to store subscriber information, preferences, purchase history, or any other relevant data for your email campaigns. Data Extensions can be linked to your email campaigns through Subscriber Attributes or used independently with AMPscript to create highly personalised content.

Querying Data Extensions Using AMPscript Functions

To query data extensions with AMPscript, you can use LookupRows, LookupOrderedRows, and Lookup functions. These functions enable you to retrieve records from data extensions based on specific criteria.

a. LookupRows:

This function returns a rowset of records from a data extension based on the specified criteria.

Example:

%%[
  var @subscribers, @country
  set @country = "Australia"
  set @subscribers = LookupRows("Subscribers", "Country", @country)
]%%

b. LookupOrderedRows:

This function returns a rowset of records from a data extension based on the specified criteria and orders the results.

Example:

%%[
  var @products, @category
  set @category = "Consoles"
  set @products = LookupOrderedRows("Products", 5, "Price DESC", "Category", @category)
]%%

c. Lookup:

This function returns a single value from a data extension based on the specified criteria.

Example:

%%[
  var @subscriberName, @subscriberKey
  set @subscriberKey = "123456789"
  set @subscriberName = Lookup("Subscribers", "Name", "subscriberKey", @subscriberKey)
]%%

Adding and Updating Data in Data Extensions

To add and update data in data extensions using AMPscript, you can use the InsertData, UpdateData, and UpsertData functions.

a. InsertData:

This function inserts a new record into a data extension.

Example:

%%[
  var @subscriberKey, @name, @email
  set @subscriberKey = "123456789"
  set @name = "Jane Doe"
  set @email = "jane.doe@example.com"
  InsertData("Subscribers", "subscriberKey", @subscriberKey, "Name", @name, "Email", @email)
]%%

b. UpdateData:

This function updates an existing record in a data extension based on the specified criteria.

Example:

%%[
  var @subscriberKey, @newEmail
  set @subscriberKey = "123456789"
  set @newEmail = "jane.doe_new_email@example.com"
  UpdateData("Subscribers", 1, "subscriberKey", @subscriberKey, "Email", @newEmail)
]%%

c. UpsertData:

This function updates an existing record if it exists, or inserts a new record if it does not.

Example:

%%[
  var @subscriberKey, @name, @email
  set @subscriberKey = "123456789"
  set @name = "Jane Doe"
  set @email = "jane.doe@example.com"
  UpsertData("Subscribers", 1, "SubscriberKey", @subscriberKey, "Name", @name, "Email", @email)
]%%

Personalising Email Content Based on Data Extension Values

By using AMPscript in conjunction with Data Extensions, you can personalize your email content based on the stored values. This can help you create more engaging and relevant email campaigns.

Example: Suppose you have a data extension called "Subscribers" with the columns: "SubscriberKey", "Name", "Email", "Country", and "Preferred_Product_Category".

First, retrieve the subscriber's preferred product category:

%%[
  var @subscriberKey, @preferredCategory
  set @subscriberKey = _subscriberKey
  set @preferredCategory = Lookup("Subscribers", "Preferred_Product_Category", "subscriberKey", @subscriberKey)
]%%

Next, use the retrieved value to display personalised content:

%%[ if @preferredCategory == "Electronics" then ]%%
  Check out our latest deals on electronics!
%%[ elseif @preferredCategory == "Fashion" then ]%%
  Discover the newest trends in fashion!
%%[ else ]%%
  Explore our wide range of products!
%%[ endif ]%%

Conclusion

AMPscript and Data Extensions are powerful tools that, when combined, enable you to create highly personalised and dynamic email campaigns. In this tutorial, we covered how to query, add, and update data in data extensions using AMPscript, as well as how to personalize email content based on data extension values. By leveraging AMPscript and Data Extensions, you can elevate your email marketing efforts and deliver more engaging and relevant content to your subscribers.

Tags:

AMPscript, Marketing Cloud, Personalisation