Hacks for Creating Dynamic Content
Inserting Contacts and Variables
Contact Property | Variable Name in Email Campaign | Import File Column Name |
---|---|---|
Email address | $SUBSCRIBER.EMAIL | Email address - work Or, Email address - home |
First name | $SUBSCRIBER.FIRSTNAME | First name |
Last name | $SUBSCRIBER.LASTNAME | Last name |
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 name | $SUBSCRIBER.STATENAME | State |
Postal (zip) code | $SUBSCRIBER.POSTCODE | Zip/Postal Code |
Home phone number | $SUBSCRIBER.HOMEPHONENUMBER | Phone number - Home |
Job title | $SUBSCRIBER.JOBTITLE | Job Title |
Custom field n (n=1-15) | $SUBSCRIBER.CUSTOMTEXTn | Custom field n |
Please note: When using the normal email editor (instead of the custom code option) head to the “Contact Details” section to merge this dynamic content into your campaign. The above instructions won’t work for the online templates as these work differently.
Inserting Contact Fields
If the above table doesn’t allow you to pull the data you want, try the custom field property, which enables you to store unique information about each of your contacts. Custom fields can be created ahead of time or while you’re updating/adding your contacts from a file.
Custom Field Limits
- 50 characters max in the API. To put together longer content, use multiple custom fields.
- 15 custom fields (max) can be used.
- If you’re using a bulk method to import or using individual contact API endpoints, then specific custom field names must be used for the API: Use the format “Custom Field n” where n = 1-15.
An example Contact Import file is:
Email Address - Home | First Name | Custom Field 1 | Custom Field 2 | Custom Field 3 |
---|---|---|---|---|
[email protected] | Dave | Soccer | American Football | Saturday, September 20th |
[email protected] | John | Baking | Sushi Making | Wednesday, January 15th |
[email protected] | Sarah | Welding 101 | Hobby Electronics | Monday, December 5th |
Inserting Custom Content into Your Campaign
In the above example, the first name, email address, and 3 custom fields are what’s going to be pulled into the recipient’s custom content. This is the HTML that’s entered into the “Advanced Editor” part of a custom code email campaign or the email_content field in the API.
To put your content in, you must choose the XHTML option (you’ll also be presented with a HTML option). And here’s what your content will look like:
Dear $SUBSCRIBER.FIRSTNAME, Thank you for being a part of our $SUBSCRIBER.CUSTOMTEXT1 class! We thought you'd also like this $SUBSCRIBER.CUSTOMTEXT2 class, offered next $SUBSCRIBER.CUSTOMTEXT3. <a href="http://placeholder.com/classes?email=$SUBSCRIBER.EMAIL">Click here to Register!</a> I hope to see you there! Sincerely, Your friends at Soccer United Co.
Tips for Adding Contacts Directly from Your Website or Application
This simple post URL allows you to add contacts into your Constant Contact account without the need to redirect your customer to the Constant Contact website to finish filling the form in.
The code below focuses on how you can construct the raw request and will require your website to make a HTTPS call to https://visitor2.constantcontact.com/api/signup.
Authentication
The “ca” value is unique to each Constant Contact account. To find what yours is, log into your account and go to Contacts, then Sign-Up Tools, and Embed Code. Simply copy the code provided, find the “ca” parameter, and paste the value into the URL for your sign-up form.
An example of the ca id in an embed code:
name= "ca" type= "hidden" value= "12345-678-910" data-id= "ca:input"
Contact Fields
Name | Required? | Description |
---|---|---|
address_city | The contact’s city. | |
address_country | The contact’s country | |
address_postal_code | The contact’s ZIP code | |
adress_state | The contact’s state | |
anniversary_day | Must include anniversary_year and anniversary_month - accepts numbers 1 to 31 | |
anniversary_month | "Must include anniversary_year and anniversary_day - accepts numbers 1 to 12 " | |
anniversary_year | "Must include anniversary_day and anniversary_month - accepts numbers 1900 + and numbers that go up to 10 years into the future " | |
birthday_day | Must include birthday_month - accepts numbers 1 to 31 | |
birthday_month | Accepts numbers 1 to 12 | |
ca | Yes | Campaign Activity ID (as explained above) |
company | company | |
Yes | The contact’s email address | |
first_name | First name | |
job_title | Job title | |
last_name | Last name | |
List (or the variations lists, list_n) | List IDs the contact’s going to be subscribed to. You can differentiate each list with “list_1” “list_2” and so on. If left blank, the contact will be automatically added to the list detailed in the sign-up form found in the product UI. | |
phone | Phone number | |
url | URL the subscriber will be redirected to once they’ve submitted the form. If left blank, a 200 success response will be returned. |
If the email address is already held in your account, their record will be updated. The contact will remain on all of the lists they’re already subscribed to.
Example URL
A URL that could be constructed to add a customer to a number of lists:
https://visitor2.constantcontact.com/api/signup?ca=xxxxx&[email protected]&first_name=Joe &list=xxxx&list=xxxxx
Creating a Sign-up Form
This is an example of a sign-up form you can embed in your website. This form will send contacts into the specified list on your account’s sign-up form. The code below sends them to a new page after their information has been submitted.
Copy and paste code strip:
Join our email list to receive updates and specials!
Unminified code:
The above sends the contact to Constant Contact. Replace the link with your own URL and your own custom “Thank you for signing up to our form” webpage, beginning with HTTP.
If there’s an error when a contact’s submitted, the above form will send them to the Constant Contact page, visitor2.constantcontact.com, displaying an error to the user.
To keep the user on their current page when they submit the form, a more advanced script is needed. An example jQuery is included below.
1. jQuery CDN that’s inserted into the header of your page
Copy and paste code strip:
Unminified code:
2. The script that processes the form
Copy and paste code strip:
$(document).ready(function() { // process the form $("#ctct_signup").submit(function(event) { // get the form data var formData = $("#ctct_signup").serialize(); // process the form $.ajax({ type : 'POST', // HTTP method, always use POST for our form url : 'https://visitor2.constantcontact.com/api/signup', data : formData, // serialized form data dataType : 'json', // the type of data we expect back from the server success: function(data){ $("#ctct_signup").replaceWith("
Thank you for joining our mailing list!
“); }, error: function(response) { $(“#ctct_signup”).replaceWith(”
The server returned an error: Status ” + response.status + “: ” + response.responseText + ”
“); } }); // stop the form from submitting the normal way and refreshing the page event.preventDefault(); }); });
Unminified code:
3. The HTML form (that your contact will see)
Join our email list to receive updates and specials!
Copy and paste code strip:
Join our email list to receive updates and specials!
Unminified code:
Note that there are three parts to this form: the jQuery header, the jQuery script, and the HTML form.
Source: http://techblog.constantcontact.com/api/release-updates/announcing-a-new-signup-form-post-url/
How to Test Your XML
Using RESTClient as a tool enables you to test your XML as well as how you’re using the APIs in Constant Contact. It’s an easy way to test individual calls outside your program to see if you’re correctly calling APIs. If you’ve made an error you’ll be provided with detailed error messages.
To start with, download and install the RESTClient here.
Then, set up your authentication information in Constant Contact by clicking the “Auth” tab before checking “BASIC” and unchecking “Preemptive”.
Enter {API KEY}%{Constant Contact username} in the “Username” section and your password in the relevant field.
Using RESTClient
You’ll tend to work with the tabs – “Method”, “Headers”, and “Body”.
In the “Method” tab – choose the appropriate method. If you’re using the GET method, you won’t need to use the other two tabs. But if you’re using POST or PUT, you’ll need to put your XML in the “Body” tab, adding “application/atom+xml” in the “Content-Type” header. If you’re trying to run GET followed by POST or PUT, you don’t need to delete the contents in the “Body” and “Headers” tabs as they’ll be ignored.
In URL, enter your API call as follows (always using https instead of http):
https://api.constantcontact.com/ws/customers/{username}/lists
Examples
1. Getting a list of contacts
Choose “GET” on the “Method” tab.
Enter https://api.constantcontact.com/ws/customers/testuser/contacts in the URL.
Hit the button that displays the “>>” icon.
Now, the RESTClient will display a response status in the lower pane – this should be 200 OK.
If your call was successful, in the BODY tab you can inspect the response body. This is often useful when putting together a Request Body for an update (PUT) or create (POST) command.
2. Creating a new contact list
Choose “POST” on the “Method” tab.
Enter “Content-Type” in the “Key” section of the “Headers” tab, and “application/atom+xml” as the “Value”. To add, just hit the plus button.
Enter your XML entry on the “Body” tab for your new contact list.
In the URL, put – https://api.constantcontact.com/ws/customers/testuser/lists
Hit the button that displays the “>>” icon.
Source –
https://community.constantcontact.com/t5/Documentation/How-To-Use-RESTClient/ba-p/24915