When sending a campaign email, it can be convenient to pull content from your site. This can help you:
To accomplish this, you can populate the Data Feed URL field under the Advanced tab in the Campaign Mail editor, or pass the data_feed_url parameter to your blast API call. This URL will be requested once immediately prior to your blast being mailed.
You can also save Data Feeds to your account for easy access. Using the Data Feed Editor, you can edit a feed's items once ingested into Sailthru. This allows you to reorder or delete feed items before a template parses the feed.
Sailthru has a generic type of data feed that is well-suited to being parsed and handled within your messages.
It is a JSON format that looks like this:
{"content":
[
{"title" : "Article Title #1",
"url" : "http://path/to/url",
"tags" : ["tag-1", "tag-2", "tag-3"],
"description" : "Description of article here",
"image" : "http://path/to/image.jpg"},
{"title" : "Article Title #2",
"url" : "http://path/to/url2",
"tags" : ["tag-5", "tag-6", "tag-7"],
"description" : "Description of article here",
"image" : "http://path/to/image2.jpg"}
]
}
If you set up your data feeds using Sailthru's Data Feed Manager, your RSS feeds will automatically be converted to Sailthru Content Feed format. Also, if you generate a feed directly from your Sailthru content database, it will be in Sailthru Content Feed format.
Here are some examples of Zephyr code to pull specific values from the above feed. If you are not familiar with programming, note that arrays start with "0" and not "1".
| Variable | Feed Value |
|---|---|
{content[0].title} | Article Title #1 |
{content[1].title} | Article Title #2 |
{content[1].tags[1]} | tag-6 |
You can loop through them in a template like so:
{foreach content as c}
<a href="{c.url}">{c.title}</a>
{/foreach}
Tip: You can force this JSON to render as RSS by adding &format=rss to the end of a Sailthru Content Feed URL. This URL is displayed when clicking the magnifying glass next to the feed on the main Data Feeds page, i.e. http://cb.sailthru.com/ws/feed?id=abcde123456&format=rss
If you don't want to manage your data feeds using Sailthru's interface, but want to instead use your own custom feeds served from your site, read on.
Using Sailthru's Feed Manager Interface, you can merge two or greater feeds. This will add a more complex JSON feed to your feed library, which you can use to populate templates/campaigns.
key for each feed. This key will be used in the merged feed and will be required in your Zephyr templating code. See the following example of a merged feed for a detailed example.
For this example, we merged together two feeds, one with the key "Firstfeed" and another with the key "Secondfeed".
{
"Firstfeed" : {
"content" : [
{
"title" : "First Feed Article Title #0",
"url" : "http://path1/to/url0",
"description" : "First Feed Article Description #0",
"content" : "First Feed Content #0"
},
{
"title" : "First Feed Article Title #1",
"url" : "http://path1/to/url1",
"description" : "First Feed Article Description #1",
"content" : "First Feed Content #1"
}
]
},
"Secondfeed" : {
"content" : [
{
"title" : "Second Feed Article Title #0",
"url" : "http://path2/to/url0",
"description" : "Second Feed Article Description #0",
"content" : "Second Feed Content #0"
},
{
"title" : "Second Feed Article Title #1",
"url" : "http://path2/to/url1",
"description" : "Second Feed Article Description #1",
"content" : "Second Feed Content #1"
}
]
}
}
Here are some examples of Zephyr code to pull specific values from the above feed. If you are not familiar with programming, note that arrays start with "0" and not "1".
| Variable | Feed Value |
|---|---|
{Firstfeed.content[0].title} | First Feed Article Title #0 |
{Secondfeed.content[1].url} | http://path2/to/url1 |
{Secondfeed.content[0].content} | Second Feed Content #0 |
Content Feeds are Horizon-powered feeds based on content crawled by the Horizon spider or manually added to the system via API.
Create a Content Feed by clicking the "Add Content Feed" button within the Data Feed page.
In addition to an array of content, the JSON provides meta data from the feed description in the Feeds page. This data includes:
For this example, consider a Content Feed set up with the following information:
This set up yields the following feed meta information when viewing the JSON:
"feed" : {
"name" : "Content Feed Name",
"url" : "http://cb.sailthru.com/ws/feed?id=1234567",
"filter_tags" : [
"demo-tag",
"demo-tag-2",
"demotag3"
]
},
Here are some examples of Zephyr code to pull specific values from the above feed.
| Variable | Feed Value |
|---|---|
{feed.name} | Content Feed Name |
{feed.url} | http://cb.sailthru.com/ws/feed?id=1234567 |
{feed.filter_tags[2]} | demotag3 |
The most flexible custom data feed format is JSON. If you provide your data in JSON format, you must use the MIME Content-type header application/json or text/javascript.
In JSON format, you can pass any data you want in the form of a single JSON object. The top-level keys of the object represent replacement variables in the body of your message. For example, if you had the feed:
{"main_title":"Today's Email Blast",
"headlines":[{"title":"Headline 0","url":"http://example.com/headline-0"},
{"title":"Headline 1","url":"http://example.com/headline-1"}]}
You could reference the variables in your editor with {main_title} or {headlines[0].title}. If you're not familiar with programming, please note that arrays, such as the above, always start at "0" not "1".
| Variable | Feed Value |
|---|---|
{main_title} | Today's Email Blast |
{headlines[0].title} | Headline 0 |
XML feeds are converted to JSON in a fairly straightforward way:
@attribute#text.For example, if your XML looks like:
<myxml> <main_title>My Main Title</main_title> <headline title="Headline 1">http://example.com/headline-1</headline> <headline title="Headline 2">http://example.com/headline-2</headline> </myxml>
Then:
| Variable | Feed Value |
|---|---|
{myxml.main_title} | My Main Title |
{myxml.headlines[0]['@title']} | Headline 1 |
{myxml.headlines[1]['#text']} | http://example.com/headline-2 |
If are creating a new feed specifically for Sailthru and you have a choice of whether to use XML or JSON, use JSON as it is more straightforward. But XML is very convenient when you are using existing feeds, such as…
Since RSS feeds are a common XML feed that most sites already have, it's easy to use your existing RSS feed as your data feed with little development effort.
Typically, you will loop through the rss.channel.item array and print each title and link. This can be accomplished as follows:
{foreach rss.channel.item as item}
<a href="{item.link}">{item.title}</a> <br/>
{/foreach}
However, this use of RSS feeds is discouraged in favor of using the Sailthru Feed Manager to convert your feeds to Sailthru content feeds (see Sailthru Content Feed Format above).
First Item
This is the first Item in our example feed
Second Item
This is the second Item in our example feed
Third Item
This is the third Item in our example feed
You can also just get a piece of HTML and put it into your email. This approach is discouraged, as it is better to separate your content from presentation, but it is supported.
Simply serve your data feed content as text/html and the entire contents of the feed will go into a replacement variable which you can reference as {html}.
Weird things happen sometimes, and you definitely don't want to send a million people content from a broken data feed. Sailthru will automatically cancel any mass mail and send an error notification when the data feed returns a non-200 HTTP status code.
For this reason, you should deliberately error out if your feed does not contain enough data, or seems to contain bad data.
For instance, if you are generating a feed that is supposed to contain five articles from the last 24 hours, and there are only three articles in your database, you should generate an HTTP error code so that Sailthru won't mail out the incomplete dataset. In PHP, for example. you can do that like so:
if (sizeof($articles) < 5) { header("HTTP/1.1 500 Internal Server Error"); echo "Not enough articles found\n"; exit; }
This tells Sailthru "something's wrong, don't use this feed".
Check out our video walk through and other videos on our vimeo channel for more step by step guides and tutorials.