What is AMPscript used for in Salesforce Marketing Cloud?
AMPscript personalizes and controls content in Marketing Cloud messages and pages, such as inserting subscriber attributes or choosing content with conditional logic.
Learn the core AMPscript building blocks for personalization, conditional logic, and dynamic content in emails, landing pages, and content blocks.
AMPscript helps you personalize content and add logic to your Marketing Cloud assets.
Display a subscriber’s first name, email address, or attributes directly in your content.
Apply IF/ELSE conditions to show different content based on subscriber data.
Switch content sections using data-driven rules and audience attributes.
Read values from Data Extensions and use them within emails and landing pages.
AMPscript is wrapped in script tags like %%[ ... ]%% so SFMC can process it during send or render.
Use Output() to display values such as first names, product names, or promo codes.
Use IF/ELSE to decide what content should appear based on subscriber data.
Store values in variables to reuse them in your email or landing page content.
%%[
SET @firstName = AttributeValue("FirstName")
IF NOT EMPTY(@firstName) THEN
SET @greeting = Concat("Hello ", @firstName)
ELSE
SET @greeting = "Hello there"
ENDIF
]%%
<p>%%=v(@greeting)=%%</p>
%%[
SET @country = AttributeValue("Country")
IF @country == "US" THEN
SET @offer = "Free shipping on orders over $50"
ELSE
SET @offer = "Free shipping on orders over $75"
ENDIF
]%%
<p>%%=v(@offer)=%%</p>
%%[
SET @productName = "Spring Collection"
SET @link = Concat("https://example.com/products/", Lowercase(@productName))
]%%
<a href="%%=RedirectTo(@link)=%%">View %%=v(@productName)=%%</a>
AMPscript personalizes and controls content in Marketing Cloud messages and pages, such as inserting subscriber attributes or choosing content with conditional logic.
You can use AMPscript in supported Marketing Cloud email, landing page, and content-block contexts. The data available to a script depends on the context in which the content is rendered.
Test with representative subscriber data in the appropriate Marketing Cloud preview or test-send context, and check both populated and missing-attribute cases. The SFMCpulse playground is for practice and does not connect to a live account.
Try your own AMPscript snippets and personalize content in the interactive playground.