Target Emails Better: Marketing Cloud Exclusion Scripts

Target Emails Better: Marketing Cloud Exclusion Scripts

Target Emails Better: Marketing Cloud Exclusion Scripts

Exclusion scripts can be leveraged to limit the number of emails sent to a specific subscriber or to stop the email from being sent based on a specific condition. It allows us to define custom exclusion logic which is evaluated at the send time. Exclusion scripts make use of Ampscript expressions which evaluates to suppress the user from sending the emails. This feature is available in several applications in the marketing cloud.

The following ways allow us to use the Exclusion script in email configuration

  • Content builder
  • Journey Builder
  • Triggered sends
  • Automation studio

 

Let’s review how exclusion scripts can be implemented in different applications in the marketing cloud.

1. Content Builder:-

  • Go to Email Studio
  • Under the Content Builder Emails tab, click on the email that needs to be sent
  • On the top-right, click on the ‘Send’ button
  • While configuring Step 2 (SELECT AUDIENCE), click on ‘Advanced Exclusions’ on the right-bottom to see the ‘Exclusion Script’ option.

 

2. Journey Builder:-

  • Go to the Journey
  • Click on the Email Activity and select the Email
  • Select the Delivery Options tab on the left to see the ‘Exclusion Script’ option.

 


Some of the Ampscript examples for Exclusion Script in Journey Builder Email Sends.

Basic script checking if the email address exists in a referenced data extension:

ROWCOUNT(LOOKUPROWS(“Exclusion_DEName”,”EMAIL_ADDR_FIELD_NAME”, EMAILADDR))>0

In this example, the ‘Exclusion_DEName’ contains a field titled ‘Email_Addr_Field_Name’ and this field contains email address values. The Personalization String ‘emailaddr’ captures the subscriber’s email address that is being rendered for the send. This will be determined by your Default Email Address within the Journey. If your Subscriber email address can be matched to an ‘Email_addr_field_name’ value in the ‘Exclusion_DEName’  data extension, then a value of 1 is returned through the RowCount(LookUpRows()) functions.

Since 1 is greater than 0, the contact would return a value of true, your contact would be excluded from the send.

Exclusion script that uses AMPscript in a Code Snippet:-


Code Snippet is a piece of content that can include HTML or AMPscript code and can be created using the below path:-

Content Builder -> Create -> Content Blocks -> Code Snippet

Step 1 –
Add the below code to a Code Snippet block:
%%[
SET @count = RowCount(LookupRows(“DataExtension_Name”,”Email_Field”, emailaddr))
]%%
%%=v(@count)=%%

Step 2 –
The following exclusion script is then used to output the result from the Code Snippet:
TreatAsContent(ContentBlockbyId(“CODE_SNIPPET_ID”)) > 0

In addition to ContentBlockByID, the below two options can also be used:

  • ContentBlockByKey – Include the Key of the Code Snippet
  • ContentBlockByName – Include the Name of the Code Snippet

Exclusion script using OR condition to check multiple data extensions:

(RowCount(LookupRows(“DataExtension_Name_1”, “Email_Field”, emailaddr)) > 0)
OR
(RowCount(LookupRows(“DataExtension_Name_2”, “Email_Field”, emailaddr)) > 0)
If you want to check the email address in multiple Data Extensions, then use the expression including an OR/AND condition.

3. Automation Studio

Option 1 

  • Go to Automation Studio
  • Drag the ‘Send Email’ Activity into the workflow
  • Create a new Email Activity or select an existing one and select the email
  • While configuring Step 3 (SELECT AUDIENCE), click on ‘Advanced Exclusions’ on the right-bottom to see the ‘Exclusion Script’ option.

 


Option 2:-

  • Go to Email Studio
  • Hover over the Interactions tab and click User-Initiated Emails.
  • Click Create.
  • Enter the name and select an email
  • Under “Recipients,” click Edit Recipients.
  • Select your recipient list.
  • Under “Audience Exclusion Script,” click the plus sign (+) to expand the section.

 


4. Triggered Sends:-

  • Go to Email Studio
  • Hover over the Interactions tab and click Triggered Sends.
  • Click Create.
  • Go to Exclusion Management | Exclusion Script.


Note – Exclusion Script may not be available as an option within the Email Activity. If this is the case, please reach out to Marketing Cloud Support to enable this feature.

Now, let’s take a look at some of the examples to understand how this works.

Functions/Strings that are used in the examples below:

  • Empty – Check if the field value is empty.
  • AttributeValue – Fetch the value for the field name specified.
  • RowCount – Function to count the number of records.
  • LookupRows – Function to lookup a Data Extension.
  • DataExtension_Name – Exclusion Data Extension that includes a set of Subscribers.
  • Email_Field – Field Name used in the Data Extension.
  • emailaddr – System-defined string that checks for Subscriber’s email addresses.
  • Domain – Check the domain of an email.
  • FormatDate – Used for Date formatting.