Display Send-Time Content Contextually

You can use AMPscript to pull information from a send logging database to determine which content displays to your subscribers. Depending on the context of the displayed content, you can use a send logging database to pull different information for those contexts. For example, you can display the content current as of send time as shared Social Forward content or content viewed on a web page. You can also display the most recent content when that content is displayed in an email message.

This example shows you how to pull send-time content from a data extension so that you can use the data in your chosen context.

To use this example, the send logging feature must be enabled for your account. For more information about enabling this feature, contact your Salesforce Account Executive.

This code example pulls send-time data from a send logging data extension when the content is viewed in an email. For shared content or content viewed in a web page, the AMPscript displays the most current content.

The first block of the code sets up the variables necessary to contain the appropriate data and hold the applicable SubscriberID and JobID values. The @SendLogData lookup call references the send logging data extension and retrieves the information in the field assigned to the specific subscriber and job. The If-Else statement displays the content from the send logging data extension if that content resides in a web page or in a Social Forward context. Otherwise, the AMPscript displays the email content.

If you send the same email message more than one time, the “View As A Web Page” option can reference an earlier version of the email message that doesn’t reflect subsequent changes. To avoid this situation, reference the BatchID of the send in your AMPscript code to ensure that the correct email message is displayed as a web page. The user-defined @eventID variable either references the current send or an earlier version using the “View As A Web Page” option.

If you send the same email message more than one time and use the “View As A Web Page” option, we recommend that you use send logging. If you don’t use send logging and a recipient is removed from the data extension before the next send, their “View As A Web Page” link stops working.