Message Context Variable
Control when content is displayed or AMPscript code is executed by using the _messagecontext
variable. This variable contains information about the current rendering context for a message. You can combine this variable with conditional logic to control whether content is rendered in certain situations. For example, you can configure content so that it’s rendered on landing pages but not in emails.
The _messagecontext
variable can have these values.
Value | Context description |
---|---|
FTAF | An email that’s sent as a “forward to a friend” message. |
LANDINGPAGE | Content that’s viewed on a landing page or microsite. |
LINKRESOLUTION | A page that’s viewed as a result of clicking a link in an email. |
PREVIEW | An email that’s sent as a preview or viewed in the email editor in Email Studio. |
SEND | An email sent to a subscriber. The variable has this value when the content is viewed as an email, but it doesn’t have it when an email is viewed as a web page. |
SITE | Content that’s viewed on a CloudPages page. |
SMS | An SMS message that’s sent to a subscriber. |
SOCIAL | Email content that’s shared by using the Social Forward feature. |
VALIDATION | An email that’s validated by using the validation option in Marketing Cloud Engagement. |
VAWP | An email that was sent to a subscriber and is viewed as a web page. |
Use the message context variable anytime that you want to control what content the viewer sees. These examples describe the most common use cases.
A basic use case for the _messagecontext
variable is to change the content that the viewer sees depending on how they view it. In this example, the user sees one string of text when they view the message as an email, that is, the message context is SEND
, and the user sees a different string when they view the content as a web page.
A common use case for the message context variable is to prevent code from rendering in certain contexts. For example, if your message uses the UpsertDE() function to insert data into a data extension when a customer views an email, you don’t want to insert unnecessary data during the process of testing and previewing your emails. In this code example, the UpsertDE()
function is only executed when a subscriber views the message.