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.

ValueContext description
FTAFAn email that’s sent as a “forward to a friend” message.
LANDINGPAGEContent that’s viewed on a landing page or microsite.
LINKRESOLUTIONA page that’s viewed as a result of clicking a link in an email.
PREVIEWAn email that’s sent as a preview or viewed in the email editor in Email Studio.
SENDAn 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.
SITEContent that’s viewed on a CloudPages page.
SMSAn SMS message that’s sent to a subscriber.
SOCIALEmail content that’s shared by using the Social Forward feature.
VALIDATIONAn email that’s validated by using the validation option in Marketing Cloud Engagement.
VAWPAn 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.