Overview
This is a collection of uses of Context Data. This is not a step-by-step guide of setting up these configurations, but a breakdown of the different methods of approaching Context Data.
For a step-by-step guide of setting up Context Data, refer to Using Context Data. For more information on what Context Data is, refer to Context Data vs Engage. |
Table of Contents
Relational Data
The most common use of Context Data is using relational data. Relational Data uses Audience Data and combines it with Context Data with some form of shared information.
Store Information
City & Glory is a clothing retail store across the United States. All customer data is accessed through the Audience Data. Below is an example of the Audience Data:
Audience Data |
|||||
Account_num |
customer_num |
name |
lifetime_value |
tier_level |
preferred_store |
1234 |
5555 |
John Doe |
1250.38 |
2 |
1 |
1111 |
6485 |
Jane Doe |
866.49 |
1 |
3 |
7894 |
3346 |
Brad Pitt |
422.31 |
1 |
4 |
The “preferred_store” column is the related column. This value is used to join information from the Context Data. City & Glory adds Context Data populated with store information. Below is an example of the Context Data:
Context Data |
|||||
store_id |
address |
state |
city |
zip |
store_name |
1 |
213 Main Street |
GA |
Atlanta |
30077 |
Atlanta Location |
2 |
55 Broadway |
NY |
New York City |
20008 |
New York City Location |
3 |
33 Old Town Road |
FL |
Jacksonville |
44698 |
Jacksonville Location |
4 |
9842 Electric Ave |
CA |
San Diego |
94465 |
California Location |
Notice the correlation between the “preferred_store” of the Audience Data and the “store_id” of the Context Data. In this case, the address of the preferred store needs to be displayed in the email Template.
The Audience and Context Data exist separately and must be joined together to dynamically populate the proper store address for each customer. FreeMarker is used to join the data.
For more information on FreeMarker, read the official FreeMarker documentation. |
In this example, the FreeMarker that combines the data is:
<#assign myData = ContextData['Entry[store_id="${Recipient.preferred_store}"]']>
This FreeMarker code creates a variable called myData. The value of myData is an object that stores all the returned information from the Context Data record where the store_id is the same value as the preferred_store from the Audience. To reference a value from the Context Data, the following FreeMarker is used:
${myData.address}
The data is now joined and can be referenced throughout the email/text/sms Template easily.
For a more detailed article on configuring Context Data as relational data, read the article Using Context Data. |
Coupon Data
The Weekly Sprout is a healthy living grocery store. Each week, a newsletter is sent out with coupon deals personalized to the customer. Customers that have a higher lifetime value receive better coupons. The Audience Data stores personalized data:
Audience Data |
|||
customer_num |
name |
lifetime_value |
coupon_id |
5555 |
John Doe |
1250.38 |
1 |
6485 |
Jane Doe |
866.49 |
3 |
3346 |
Brad Pitt |
422.31 |
4 |
The Context Data contains the coupon data. The Context Data stores the details of the coupon:
Context Data |
|||
coupon_id |
coupon_code |
percentage_off |
text |
1 |
00030 |
30 |
Enjoy 30 percent off for being such a valued customer |
3 |
00010 |
10 |
Enjoy 10 percent off for this week only |
4 |
00005 |
5 |
Enjoy 5 percent off on any item for this week only |
Notice the coupon_id column in both the Audience and the Context Data. This is the value that will be used to join the data together. Using FreeMarker, this is how the relational data is combined:
<#assign myData = ContextData['Entry[coupon_id="${Recipient.coupon_id}"]']>
Now, within the Template, the relevant coupon data is rendered to the customer. In this case, the returned information would make up a large portion of the email/text/sms contact.
This example follows the same idea as the store information example. It’s a versatile approach to dynamic content.
HTML Data
Another interesting example of using Context Data is building the entire HTML Template through returned results from Context Data. It is possible to build the full email display through returned results from Context Data.
Context Data has a limit to how much data can be transferred for use within a Template. It is recommended that Context Data transmit under 5mb of data. If more data must be transferred, consider using Engage, which has no limit. |
Newfound Apparel is a rising company that offers very personalized newsletters. Based on the Audience data, entire custom formatted HTML can be generated from the Context Data. Below is an example of the Audience Data:
Audience Data |
|
|||
customer_num |
name |
lifetime_value |
template_id1 |
template_id2 |
5555 |
John Doe |
1250.38 |
1 |
4 |
6485 |
Jane Doe |
866.49 |
3 |
8 |
3346 |
Brad Pitt |
422.31 |
2 |
3 |
The Context Data for this example only has two columns:
Context Data |
|
template_id |
html |
1 |
<div id=”template_id1”>It’s been a long time since you’ve been to a store! Maybe this coupon will help! </div> |
2 |
<div id=”template_id2>It’s time, ${Recipient.name}! A big sale is headed your way! <#if Recipient.lifetime_value?number gte 1000> You’re a top spending customer. Don’t let anything get in the way of your deals this week.<#else> There are sales that you need! The sales only last this week, so get to it!</#if></div> |
3 |
<p>Hope you’re having a good day! Know what would make that day better? <b>SAVINGS</b>! Click <a href=”www.newfoundapparel.com>here</a> for the best deals of the day. |
Note that FreeMarker within the Context Data still renders successfully within the Email Template. This includes functions, variables, and conditions. |
There is still an element of relational data within this example. Instead of using the relational data to select a coupon or store information, the actual HTML of the email is stored in the Context Data.
Using the data in this example takes more than just one line of code. Because there are two items that are needed (Recipient.template_id1 and Recipient.template_id2) from the context data, multiple FreeMarker statements are needed:
<#assign
html1 = ContextData['Entry[template_id="${Recipient.template_id1}"]']
html2 = ContextData['Entry[template_id="${Recipient.template_id2}"]']
>
Placing the HTML blocks into the Email Template uses the following variable:
${html1.code}
${html2.code}
This example can be expanded on even further with dozens of different templates. CSS styling can even be used within divs and elements to create a cohesive appearance to the HTML. This is a more advanced configuration as Web Design knowledge is needed to build the HTML code within the table. Testing is required to confirm everything is rendered correctly.
Comments
0 comments
Please sign in to leave a comment.