Advanced: Dynamic Messaging/Conditional Logic Statements

Note: This is an advanced feature meant for programmers who understand VBScript or know how to implement IF-THEN statements. 

When composing the body of your email message, you may use conditional logic statements within the body to display different content to different recipients, based on the recipients' individual profiles.

For example, if you are the email marketing coordinator for an internet sporting goods store called SportsDeals.com, you may want to send out an email of current specials to all of your past customers. You may want your customers who play tennis to receive a promotion about tennis equipment and you may want your skiing customers to receive a promotion about skiing equipment. And you may want everyone else to receive a generic promotion on any product within the store.

To use conditional logic, you must use the popular Microsoft VBScript language.

Examples:

In JangoMail, VBScript statements must begin with [** and end with **].

Let's do an example to illustrate how this feature works. For this example, we'll assume you have a JangoMail list set up called "Past Customers". The fields in this list are:

EmailAddress
FirstName
LastName
DateOfLastPurchase
MainSport

We will use the dynamic messaging functionality to insert "conditions" within the Body of the email message to display different content to different recipients, based on each recipient's list profile.

Here is the body of the HTML email:

<HTML>
<BODY>
<P>Dear %%FirstName**SportsDeals.com Customer%%</P>
<P>Here are this week's special deals:</P>
<P>
[** If MainSport = "Tennis" Then **] 
Click <a href="http://www.sportsdeals.com/tennis_discount.html">here</a> to get 15% off all of our new line of tennis rackets. 
[** ElseIf MainSport = "Skiing" Then **] 
Click <a href="http://www.sportsdeals.com/skiing_discount.html">here</a> to get 10% off all of our new skis. 
[** ElseIf MainSport = "" Then **] 
Click <a href="http://www.sportsdeals.com/general_discount.html">here</a> to get 5% off any one item in our store. 
[** End If **]
</P> 
</BODY>
</HTML>

In the above example, different content is displayed to the recipient based on each's "MainSport" value. For those list members whose "MainSport" attribute is set to "Tennis", the email will advertise a 15% discount off of new tennis rackets. For those list members whose "MainSport" attribute is set to "Skiing", the email will advertise a 10% discount off of skis. And for those list members whose "MainSport" attribute is neither "Tennis" nor "Skiing", the email will advertise a 5% discount off of any one product in the store. 

Now let's take the personalization one step further. We will now personalize the email based on the date of last purchase of each recipient. Those that have not purchased anything in the last 6 months will receive an additional incentive to come back and make a purchase. 

<HTML>
<BODY> 
<P>Dear %%FirstName**SportsDeals.com Customer%%</P> 
<P>Here are this week's special deals:</P> 
<P>
[** If MainSport = "Tennis" Then **] 
Click <a href="http://www.sportsdeals.com/tennis_discount.html">here</a> to get 15% off all of our new line of tennis rackets. 
[** ElseIf MainSport = "Skiing" Then **] 
Click <a href="http://www.sportsdeals.com/skiing_discount.html">here</a> to get 10% off all of our new skis. 
[** ElseIf MainSport = "" Then **] 
Click <a href="http://www.sportsdeals.com/general_discount.html">here</a> to get 5% off any one item in our store. 
[** End If **] 
[** If DateDiff("m", CDate(DateOfLastPurchase), Now()) >= 3 Then **] 
It has been over 3 months since you've made a purchase from us! We value your business and would like to have you come back. If you come back, we'll take an additional 10% off your total order. 
[** End If **]
</P> 
</BODY>
</HTML>

In the above example, we use several built-in VBScript functions that go beyond simple If-Then-Else statements. Here we use two date functions, DateDiff and CDate, to accomplish our goal.

 

VBScript Reference: 

For a complete reference on the VBScript language, please see:

http://msdn.microsoft.com/en-us/library/d1wf56tt%28v=VS.85%29.aspx

 

Important Considerations:

  1. Use straight quotes rather than curly quotes when using strings. Use: " ".
    This will work:
    [** If MainSport = "Tennis" Then **]
    This will NOT work and will result in an error:
    [** If MainSport = “Tennis“ Then **]
  2. All fields in your list or your extracted data (if connecting to a database) are turned into variables at run-time. Make sure your field names are legitimate VBScript field names. Field names should contain only alphanumeric characters (letters and numbers) and should NOT contain spaces. Also, field names CANNOT start with a number. For example, a field named "9Lives" would result in an error if using conditional logic statements.
  3. All variables are treated as strings unless you cast them to another type. For example, if you have a List with the following fields:
    • FirstName
    • LastName
    • Age 
    And you wish to use an IF-THEN statement comparing the age of the list member to a pre-defined age, you must convert the "Age" variable to an integer type first:
    [** If CInt(Age) >= 21 Then **] 
    The same applies to variables containing dates as well. You can use the CDate function to convert the string literal to a variable of type date and you can use functions like DateAdd and DateDiff for advanced date manipulation.
  4. There may be cases where you wish to output a variable to your email message. In these cases you can use a special function called OutputString. For example, if you want to display today's date in your email, you can use:
    [** OutputString(Date) **]

 

Frequently Asked Questions:

Q: What happens if I make a mistake in the syntax of my VBScript statements? 

A: If your scripting results in an error, the email will not be sent to the recipient, and the email manager on your account will receive an email notification explaining that a script processing error has occurred and the recipients have not received the email. Note that JangoMail will accept the message when you click the Send button. JangoMail does not do any validation or checking of the script at the time the Send button is clicked.

Q: What is the list of VBScript commands that can I use in my emails?

A: You can use almost all of the VBScript commands documented on Microsoft's website. The only functionality you can't use is the creation of ActiveX objects.

Q: How can I test my conditional logic code before sending out a mass email to my entire list?

A: You should set up a test list that has just enough recipients to simulate all of the "conditions" for which you have scripted your email message. For example let's say that you are planning to send to a list with 10,000 members, and the list contains the field "LastPurchaseDate", and in the body of your email you've written logic to have one set of content to display to those list members whose LastPurchaseDate is in the last 90 days and other content for those where the date is older than 90 days. To test this email before you send to your big list, set up a different test list with two members, one that has a "LastPurchaseDate" equal to within 90 days from the present, and one where the attribute is set to a date older than 90 days. You can then send to this test list and see both versions of the email.

Q: What happens if I preview an email with conditional logic statements?

A: JangoMail's preview functionality allows you to send a test email to an email address of your choice. The preview functionality does not render personalization or conditional logic statements. When you preview an email with conditional logic statements, the preview engine will assume that all of the variables within the script are empty. For example, if you have written an IF-THEN-ELSE statement such as… 
[** If State = "OH" Then **] 
You live in Ohio. 
[** Else **] 
You do not live in Ohio. 
[** End If **] 
…then if this email is previewed, the "You do not live in Ohio" line will render in the email, because the preview engine assumes that the "State" is equal to nothing.

Q: I am using the built in JangoMail HTML editor, and I noticed that the editor has put HTML tags within my blocks of script. Will this prevent my script code from rendering properly?

A: No, the script will still process properly. When the JangoMail script-processing engine goes to work, it removes any HTML tags that are in between the [** and **] delimiters.

 Q: Is the JangoMail support staff available to help me implement scripts or debug a script that I wrote?

A: Yes, but this is not part of JangoMail's standard, free support. This type of support is billed based on time needed by the JangoMail technician to assist you. For more information, please contact the JangoMail support team.

 

Discover more of JangoMail's advanced features!

 Last Updated: 10.27.14 AE

Have more questions? Submit a request
Powered by Zendesk