Skip to main content

AMPscript Day 2- Part 2

SMFC AMPscript IF Condition - 10 Real-Time Use Cases

The AMPscript IF Condition is one of the most commonly used personalization techniques in Salesforce Marketing Cloud (SFMC). It enables marketers to display different content to subscribers based on specific criteria such as customer status, location, age, loyalty tier, subscription plan, or any other data stored in a Data Extension.

Using conditional logic, AMPscript evaluates whether a condition is TRUE or FALSE and dynamically displays the appropriate content. This helps create highly personalized and relevant email experiences, improving customer engagement and campaign effectiveness.

In this blog, we'll explore 10 practical AMPscript IF Condition use cases that demonstrate how to personalize email content based on subscriber attributes and data-driven rules.

Data Extension:





1. Gold Customer:

Code:

%%[Set @Status=AttributeValue("Status")]%%

%%[IF @Status=="Gold" Then]%%

Welcome Gold Member!

%%[ENDIF]%%

Gold Customer

 Bronze/ Silver Customer > No output



2. Age Eligibility

Code:

%%[Set @Age=AttributeValue("Age")]%%

%%[IF @Age >=18 Then]%%

You are Eligible

%%[ENDIF]%%

Output: You are Eligible


No Output


3. India Customer

 Code:

%%[Set @Country=AttributeValue("Country")]%%

%%[IF @Country =="India" Then]%%

Free Shipping

%%[ENDIF]%%

Output: Free Shipping


Output: No Output


4: Birthday

Code:

%%[Set @IsBirthday=AttributeValue("IsBirthday")]%%

%%[IF @IsBirthday=="True" THEN]%%

Happy Birthday!

%%[ENDIF]%%

Output:



5. Cart Value

Code

%%[Set @CartValue=AttributeValue("CartValue")]%%

%%[If @CartValue>="2000" THEN]%%

Extra Rewards

%%[ENDIF]%%



6. Email Exists

Code

%%[Set @Email=AttributeValue("Email")]%%

%%[IF NOT EMPTY (@Email) THEN]%%

Email Verified

%%[ENDIF]%%

Output:



7. Premium Plan

Code

%%[Set @Plan=AttributeValue("Plan")

%%[IF @Plan=="Premium" Then]%%

Premium Content

%%[ENDIF]%%

Output:



In the same, using the ELSE Code:

%%[Set @Plan=AttributeValue("Plan")

%%[IF @Plan=="Premium" Then]%%

Premium Content

%%[ELSE]%%

No Content

%%[ENDIF]%%



8. High Salary

Code

%%[Set @Salary=AttributeValue("Salary")]%%

%%[IF @Salary>="5000" THEN]%%

Bonus

%%[ENDIF]%%

Output:





9. Active Customer

%%[Set @CustomerStatus=AttributeValue("CustomerStatus")]%%

%%[IF @CustomerStatus=="Active" THEN]%%

Special Offer

%%[ENDIF]%%

Output:



10. Mobile Exists

Code

%%[Set @Mobile=AttributeValue("Mobile")]%%

%%[IF NOT EMPTY (@Mobile) THEN]%%

SMS Enabled

%%[ENDIF]%%

Output

If mobile number exists, you will see output as "SMS Enabled"

If mobile number doesn't exists and there is no "ELSE" code provided, you will see no output.



Takeaways:

  • IF conditions are used to display dynamic content based on subscriber data stored in a Data Extension or profile attributes. 
  • AMPscript evaluates the condition and displays content only when the condition is TRUE. 
  • If the condition is FALSE and no ELSE statement is provided, no content is displayed.  AttributeValue() is commonly used to retrieve subscriber data safely.
  • Conditional logic enables highly personalized email experiences without creating multiple email versions.

  • Common Mistakes to Avoid Missing ENDIF. 

    Forgetting to set variables before using them. 
    Incorrect field names that don't exist in the Data Extension. 
    Missing quotation marks around text values. 
    Not testing both TRUE and FALSE conditions. 
    Expecting output when no ELSE statement exists.

    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