The data that these ESL examples make use of comes from the Relational Data Service (RDS). Access to RDS details enables you to build highly complex personalization rules.
Product-recommendation is a table view which relates RDS data from different tables. Its parameter is a field on the basis of how you want to identify the contact. This identifier field is the email address in this example.
Note:
- An RDS parameter can only be a constant (a field or a string), it must remain the same.
- An RDS expression is valid only with a defined index and field name in it.
Subject line personalisation using RDS
Our goal here is to create a personalized subject line for the email using RDS data. The data we’re working on in RDS is in a view called em_othercampaign:
The reference field for this campaign is id_othercampaign, and the records are sorted by the value of the position field, in an ascending order:
- Display the title of the sale where position=1
- Display the discount associated with this first sale
- Add a comma
- Display the title for the 2nd sale
- Add a comma
- Display the title for the 3rd sale
- Add a comma
- Display the title for the 4th sale
In the ideal scenario that no field is ever empty. This can be achieved using the following code:
{#Going through the first 4 records in the view#}
{%foreach sale in rds.Connection_name.em_othercampaign('1') limit 4%}
{#Displaying the title#}
{{sale.title}}
{#If we’re in the first iteration, show the discount too#}
{%if loop.first and sale.max_discount_fmt != ''%}
{{sale.max_discount_fmt}}
{%endif%}
{#If we’re not in the last iteration, add a coma#}
{%if not loop.last%}
{%endif%}
{%endforeach%}
- All client-specific data is in bold
- The (‘1’) here is the reference field, so we’re looking in the view for records where id_othercampaign is equal to 1.
However, the title is sometimes empty as you can see in the screenshot at the top of this email.
One way to fix that is to simply perform a check to see of the title is empty:
{#Going through the first 4 records in the view#}
{%foreach sale in rds.Connection_name.em_othercampaign('1') limit 4%}
{%if sale.title != ''%}
{{sale.title}}
{%if loop.first and sale.max_discount_fmt != ''%}
{{sale.max_discount_fmt}}
{%endif%}
{%if not loop.last%}
{%endif%}
{%endif%}
{%endforeach%}
- All client-specific data is in bold
- added check whether the title is empty is in italics
However, this is not perfect because:
- If the title of the first sale is empty, we will not show any discount amount - the subject line will be a simple list of brands names.
- If all the titles for the first 4 sales are empty, there will be no data at all.
We can deal with this and build two separate foreach loops. One to create an array that will store all non-empty titles, and then the second to iterate through the created array.
{#Creating 2 arrays to store the titles and discounts#}
{%set salesNames=[]%}
{%set salesDiscounts=[]%}
{#looping through all the sales in the table, and storing the non empty titles and discounts in the arrays#}
{% foreach sale in rds.Connection_name.em_mothercampaign_today_fr('1') %}
{%if sale.title != '' %}
{% set salesNames = salesNames|merge([sale.title]|raw) %}
{% set salesDiscounts = salesDiscounts|merge([sale.max_discount_fmt]|raw) %}
{%endif%}
{%endforeach%}
{#Displaying the first 4 sales that do have a title#}
{% foreach saleWithTitle in salesNames limit 4 %}
{{saleWithTitle|title}}
{%if loop.first and salesDiscounts[0] != ''%}
{{ salesDiscounts[0]|lower }}
{%endif%}
{%if not loop.last%}
,
{%endif%}
{%endforeach%}
Favorite offline store
Using the purchase information available to you, gradually fill up a table to holds enough information so you can figure out which offline store is each contact's preferred one. Once you got this, incorporate it into personalizing you campaigns.
The table, your data source, could have the following columns:
- contact ID
- preferred store ID
- store name
store_id | store_name | category |
2353kl5 | Holborn | superstore |
ij44eijxs | Black Heath | outlet |
Placeholders/views:
view | description | Reference field(s) | Placeholder |
stores |
personalize the email sender address If the field "favorite_store"(field ID = 7070) is empty, then we show the fallback sender name |
external_id (=suite field id 7070) | {{ rds.rds_acme_us.stores(<external_id>)[0].name }} {{ rds.rds_acme_us.stores(contact.7070)[0].name }} |
Use a personalization placeholder to show the store name, for example, in the email sender name field. store_id
can serve as the identifier in this case. This marketing move gives the contact the impression that their preferred store is writing to them.
Store-specific data in footers
Prepare a relational data table (MySQL, for example) with the store opening time, address, phone number and so on. When you reach out to your contacts in a campaign you can make their lives easier by including the details for their nearest or favorite store:
1 Store Name: {{ rds.rds_ACME_us.storesUS(contact.7904)[0].storeName }}
2 Store Email: {{ rds.rds_ACME_us.storesUS(contact.7904)[0].storeEmail }}
3 Store Street: {{ rds.rds_ACME_us.storesUS(contact.7904)[0].storeStreet }}
4 Store City: {{ rds.rds_ACME_us.storesUS(contact.7904)[0].storeCity }}
5 Store State: {{ rds.rds_ACME_us.storesUS(contact.7904)[0].storeState }}
6 Store Phone: {{ rds.rds_ACME_us.storesUS(contact.7904)[0].storePhone }}
7 Store Fax: {{ rds.rds_ACME_us.storesUS(contact.7904)[0].storeFax }}
8 Store BusinessHours: {{ rds.rds_ACME_us.storeBusinessHoursUS(contact.7904,contact.8052)
You can even add more marketing content and advertise specific events or services available in certain stores:
{% foreach e in rds.rds_ACME_us.eventsView(contact.7904,contact.8052) limit 1%} Event Name: {{ e.eventTitle }} Event Date: {{ e.eventStartDate }} - {{ e.eventEndDate }} Event Description: {{ e.eventDescription }} {% endforeach %}