Creating Dynamic Content Using the CTCT API

Dynamic content – What is it? Why do I want to know about it?

Campaigns that include content personalized to each subscriber are shown to have a higher engagement level with their audience. Merging dynamic content into a campaign is a like a 3 step dance, a waltz. Get ready, on three…

Step_One:rsrrpac Decide what dynamic content you want to appear in the email campaign.
Choose from the standard contact properties (see section below), or use Custom Fields to include other content dynamically for each subscriber.
Step_Two:srrpac Make sure that your subscriber records include all the dynamic content you want to merge into the campaign.
Step_Three:srrpac Place the dynamic content variables in the campaign where you want it to appear.

What we’re building

To demonstrate the technics explained here, we will create a simple email campaign that announces a restaurant’s new menu, shown here. There are two dyanamic elements in this campaign:

  1. a photo of meal from the menu – the photo used is based on subscriber preference, either fish, chicken/turkey/fowl, game, or beef
  2. a link to the recipe for that meal, again, based on subscriber preference.

The HTML of the email campaign includes variables which are replaced by the values stored in each individual contact record at the time the email campaign is sent.  This works exactly like the merge feature in Microsoft Word.  The variables are used to make the value for the image source and “Get the Recipe!” link in the HTML personalized for each recipient.


Step One: Contact properties and variables

Contact variables are the placeholders for the dynamic content that will appear in the campaign. Insert the variable for the contact property in the content of the campaign to make it personal. Below is the list of contact variables that you can use to pull personalized information from each contact record into a campaign, including Custom Fields.

Contact Property Variable name Import File Column name
Email address $Subscriber.Email Email Address, E-mail Address or Email
First name $Subscriber.Firstname First name
Middle name $Subscriber.Middlename Middle name
Last (family) name $Subscriber.Familyname Lastname
Mailing address line 1 $Subscriber.AddressLine1 Address Line 1
Mailing address line 2 $Subscriber.AddressLine2 Address Line 2
Mailing address line 3 $Subscriber.AddressLine3 Address Line 3
Mailing address city $Subscriber.City City
State two-letter code $Subscriber.StateCode State
Statename $Subscriber.Statename State
Postal (zip) code $Subscriber.PostalCode Postal Code
Sub Postal (zip) code $Subscriber.SubPostalCode Sub Postal Code
Country code $Subscriber.Country.Code Country
Country name $ Country
Home phone number $Subscriber.HomePhoneNumber Home Phone
Company name $Subscriber.Companyname Company name
Work phone number $Subscriber.BusinessPhoneNumberspace Work Phone
Job title $Subscriber.JobTitle Job Title
Note $Subscriber.Note Note
CustomField n (n=1 – 15) $Subscriber.CustomTextn Custom Fields

Step Two: Custom Fields

The Custom Field property in the contact resource allows you to store information about each contact that is unique to your needs or business. You can create custom fields ahead of time or on the fly while you are adding or updating your contacts from a file (use the column name shown in the table when importing or updating contacts using either of the bulk activities add contacts endpoints-mulitpart or JSON).

CustomField limitations

  • Max character limit – CustomFields are limited to 50 characters; use multiple custom fields to string together longer content.
  • Max number of CustomFields – each contact is limited to 15 CustomFields
  • CustomField names – The API supports very specific CustomField names that must be in the format of CustomFieldn, where n = 1 – 15.

Add dynamic URLs and image links in CustomFields

BEST PRACTICE Break URLS into 3 or more sections, depending on the length of a link – each section requires one CustomField. One of these sections is the part of the link that is unique for each subscriber. In the examples that follow, it is the image and link filename that is unique to each subscriber.

  • First section – beginning of the link, up to just before the field in the URL that is unique for each subscriber.
  • Second section – part of the link that is unique to each subscriber.
  • Third section – closing section of the link.
Link Beginning  Dynamic part Link Close
<img src=” CustomField1=fish.jpg /”>space
<a href=”<a  CustomField2=29193-basic-fish-tacosspace “>Get the Recipe!</a>space

What does the JSON look like in the contact?

Here is what the custom_fields array of a contact record who will be sent the campaign with the dynamic content looks like:

 "name": "CustomField1",
 "label": "CustomField1",
 "value": "fish.jpg"
 "name": "CustomField2",
 "label": "CustomField2",
 "value": "29193-basic-fish-tacos"

See a complete example of a contact record JSON file here.

Step Three: Getting Custom Content into the Campaign

Campaign JSON

In this example, the first <p> section including Custom.Text1 renders the menu item image, and the second <p> with Custom.Text2 renders the link to the recipe.

"email_content": "
We're excited to share with you our savory fall dinner menu. Our Head Chef Roger Robert's passion for great tasting meals that are healthy with ingredients sourced from local producers shines through.

Here's a meal we think you'll like so much that we've included a link to Chef Roger's recipe too!!

<strong>Your recommendation:</strong>

<p><img src=\"$Subscriber.CustomText1/\"></p>

<p><a href=\"$Subscriber.CustomText2\">Get the Recipe!</a></p>",

Leave a Comment