Data Feeds

Overview

When sending a campaign email, it can be convenient to pull content from your site. This can help you:

  • Automate your email production process by designing a template once and automatically populating it with content
  • Schedule a daily email in advance without even knowing what the content will be
  • Use Sailthru Horizon personalization to deliver custom content to users

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 Content Feed Format

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".

VariableFeed 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 Multiple Feeds

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.

  1. Access the Feed Manager at https://my.sailthru.com/feeds and use the "Merge Feeds" button
  2. Give the feed an internal name that will be used in the feed drop-down menu
  3. Add a 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.

Example Merged Feed

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".

VariableFeed 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

Using Content Feeds

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:

  • Content Feed Name
  • Content Feed URL
  • Content Feed Tag(s)
Example Content Feed Meta Information

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.

VariableFeed Value
{feed.name} Content Feed Name
{feed.url} http://cb.sailthru.com/ws/feed?id=1234567
{feed.filter_tags[2]} demotag3

JSON Data Feeds

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".

VariableFeed Value
{main_title}Today's Email Blast
{headlines[0].title}Headline 0

XML Feeds

XML feeds are converted to JSON in a fairly straightforward way:

  • Individual elements become individual keys
  • Attributes are represented as a key named @attribute
  • When attributes are mixed with content, the content is represented as #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:

VariableFeed 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…

RSS Feeds

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).

Step by Step Tutorial: RSS/XML

  1. Go to the "Campaigns" section and hit the "Create New" button.
  2. Under the advanced tab, select custom "Custom Feed URL" and enter the following URL: http://sailthru.com/service/examplerss.xml
  3. Enter the following Zephyr code:
    {foreach rss.channel.item as item}
    <h2>{item.title}</h2>
    <p>{item.description}</p>
    {/foreach}
  4. click on the HTML Preview tab, you should see:
        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

Raw HTML

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}.

Erroring

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".

Video Demo

Check out our video walk through and other videos on our vimeo channel for more step by step guides and tutorials.

 
/var/www/docs.sailthru.com/htdocs/data/pages/data-feeds.txt · Last modified: 2012/02/21 14:22 by David Studinski
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki