Skip to main content

AMP Script (Direct Reference & Attribute Value)

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:


Use case: Loyalty Points Statement Email

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

]%%


In the second HTML block, the message and the AMPScript to personalize the message:


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

Popular posts from this blog

A/B Testing

Confluence link 1:  https://elearningit24.atlassian.net/wiki/external/MzA3YWUxNjI3YzBkNGZiZmFlZTc1ZGIzYmU1ZmM1MmQ   What is A/B Testing? A/B testing, also known as split testing , is a controlled experiment where two versions of a webpage, email, ad, or any digital asset are tested against each other to determine which one performs better. Why? Higher open rates Better Engagement Increased Sales and Lead conversion Reduced unsubscribed rates Date Driven- No assumption & Proven Results Test Type Subject Line Email Content Area From Name Send Date & Time Pre Header   Email Test Template: Friendly and Personalised Straight to the point & Action Oriented Confluence Link 2:  https://elearningit24.atlassian.net/wiki/external/NDk0Zjg0ODk3YjAwNDI5ZjkxOTVmMTAxNTQ3ZjlhNmQ Subject Line A/B Test: A/B Testing Use Case: Optimizing Email Subject Lines for Higher Open Rates Scenario- Subject Line: A company wants to increase the open rates of its promotional emails in Sa...

Email Marketing Campaings

Use Cases of Standard Data Extensions 1. Customer Data Storage Scenario : A retail business wants to store customer information, such as names, email addresses, and purchase history, for email marketing campaigns. Solution : Use a standard data extension to store and manage customer data securely and efficiently. Data Extension Structure Field Name Data Type Length Required Primary Key SubscriberKey Text 50 Yes Yes FirstName Text 50 Yes No LastName Text 50 Yes No EmailAddress EmailAddress N/A Yes No PurchaseHistory Decimal N/A No No Sample Records SubscriberKey FirstName LastName EmailAddress PurchaseHistory 001 John Doe john.doe@example.com 1500.50 002 Jane Smith jane.smith@example.com 200.00 https://mc.s8.exacttarget.com/cloud/#app/Email/C12/Default.aspx?entityType=none&entityID=0&ks=ks%23Subscribers

SQl Query

  Workflow: Journey Builder> Automation Studio> New Automation Enter Query: Drag and drop Schedule in  Start with a Starting Source and the SQL Query> Choose Query> Create New Query Activity> Name your file and add your query (Field name thats part of the DE you create separately- Example: FirstName, LastName, Subscriber Key) Create a new DE in Email Studio with the query field> Select The test DE which was created: Select Target DE and Save & Run Workflow: Select All Activities and Run Workflow: Activity Details: Run Completed with updated DE Edit/ add another query: Copy Source DE and create a new DE with same fields that we are running in SQL: Run the updated SQL Query added Activity and DE updated with Records: Completed Status: Received error: When the Query field and the DE created field does not match When an existing Query is being run, if we try to run another query Fixed the error by matching same field Waiting for existing query to complete