What is AMPscript in Salesforce Marketing Cloud?
AMPscript (Advanced Marketing Personalization Script) is Salesforce Marketing Cloud's scripting language used to create personalized and dynamic content in emails, landing pages, SMS messages, and CloudPages.
Below is a demonstration of how it can be used in the Email Studio.
First create a blank email content> Name the Properties and enter the subject line> Add HTML in the Content and add your AMP script.
Direct Reference:
%%[
VAR @FirstName, @LastName, @EmailAddress, @SubscriberKey, @PhoneNumber, @City
Set @FirstName="Gurbachan"
Set @LastNameKor="Kor"
Set @EmailAddress="gurbachanshimray@gmail.com"
Set @PhoneNumber="7002585014"
Set @City="Bangalore"
]%%
%%=v(@FirstName)=%%<br>
%%=v(@LastName)=%%<br>
%%=v(@EmailAddress)=%%<br>
%%=v(@PhoneNumber)=%%<br>
%%=v(@City)=%%<br>
Attribute Value:
Below is the DE where I will be testing the AMPScript with Attribute:
Attribute is used because it Safely retrieves the attribute and Returns an empty value if not found (Fallback Values).
The AMPScript code I used for personalization is below:
%%[
VAR @FirstName, @LastName, @EmailAddress, @SubscriberKey, @PhoneNumber, @City
Set @FirstName=AttributeValue("FirstName")
Set @LastName=AttributeValue("LastName")
Set @EmailAddress=AttributeValue("EmailAddress")
Set @PhoneNumber=AttributeValue("PhoneNumber")
Set @City=AttributeValue("City")
]%%
%%=v(@FirstName)=%%<br>
%%=v(@LastName)=%%<br>
%%=v(@EmailAddress)=%%<br>
%%=v(@PhoneNumber)=%%<br>
%%=v(@City)=%%<br>
Proceed with Preview and test by selecting the DE from where the fields were used:
Business Requirement
Every month, customers receive a loyalty statement email showing:
- Customer Name
- Loyalty Tier
- Current Points Balance
- Personalized message based on points balance
So, first I need to create Email template with 2 HTML block, and CTA
In the first HTML block, I need to enter the AMPScript with the variable and the rule as per the tier for the personalized message.
In the script, we need to ensure that we are declaring all the fields from our DE in the variable. Then set the Attribute Value, make sure the attribute value matches with the DE fields and the variables added while declaring. Next, set the personalization rule for sending the dynamic content in email.
%%[
VAR @FirstName, @EmailAddress, @Tier, @PointsBalance, @Message, @CTA
SET @FirstName = AttributeValue("FirstName")
SET @EmailAddress = AttributeValue("EmailAddress")
SET @Tier = AttributeValue("Tier")
SET @PointsBalance = AttributeValue("PointsBalance")
IF @Tier == "Platinum" THEN
SET @Message = "You are one of our VIP Platinum members."
SET @CTA = "Explore Exclusive Benefits"
ELSEIF @Tier == "Gold" AND @PointsBalance >= 5000 THEN
SET @Message = "You have enough points to redeem exciting rewards."
SET @CTA = "Redeem Rewards"
ELSEIF @Tier == "Silver" AND @PointsBalance >= 1500 THEN
SET @Message = "You are close to achieving Gold status."
SET @CTA = "Upgrade Your Tier"
ELSE
SET @Message = "Keep earning points with every purchase."
SET @CTA = "View Rewards"
ENDIF
]%%
Hello %%=v(@FirstName)=%%,<br>
<br>
Tier: %%=v(@Tier)=%%<br>
Points: %%=v(@PointsBalance)=%%<br>
Message: %%=v(@Message)=%%<br>
<br>
CTA: %%=v(@CTA)=%%
Finally, preview and test by selecting the DE:
Comments
Post a Comment