« View all blog posts

A developer's introduction to Content Recommendations

Last week we launched Content Recommendations in our Web Personalization tool. If you’re a developer, you may be excited to learn that we also offer inline content recommendations that can be implemented with basic HTML.

What are Content Recommendations?

If you have Netflix, you’re probably familiar with the idea of recommended content. When you log in, Netflix will suggest new movies or TV shows based on what you’ve already watched and the genres you like.

Similarly, Lytics Content Recommendations seek to provide a unique, personalized experience for each user based on their affinity data. It’s pretty simple: Serve your users content that matches their interests and they're more likely to click it and continue engaging with your brand.

Lytics Content Affinity

If you’re not already familiar with Lytics’ Content Affinity Engine, here’s a quick run down: Our engine can crawl your website to build up an inventory of your content. During this process, we extract topics from each page using text analysis, and we also measure individual user engagement with each piece of content over time. We then translate this engagement data into user affinities, with a score from 0 to 1 measuring how interested a user is in a topic.

Content Affinity Content Affinity

This is some pretty detailed data. Alone it provides great insight into your users’ interests, but it becomes even more valuable when you can start using it for truly one-to-one marketing.

How does it work?

Using the inventory of content Lytics has built up, we can recommend content to your users when they visit your website. Our Content Recommendation API accepts an identifier for the user and returns a number of suggested documents based on that user’s affinities. We’ve built this into our Personalization SDK to make it accessible for use on your website. So if you’re a developer, adding recommendations seamlessly into your website is extremely simple.

Sounds cool, right? Let’s see it!

We use inline recommendations right here, on the Lytics blog. At the bottom of this blog post are several articles from our own blog that we recommend for you based on your affinities in Lytics. If you don't want to scroll all the way down yet, they look something like this:

Recomendations Recomendations

Implementing inline Content Recommendations

To use Lytics Content Recommendations on your website, it’s essential that you have the Lytics Javascript Tag as well as the Pathfora Personalization SDK installed on your website. We’re going to be using specially named data attributes on HTML elements. Pathfora will look for these attributes on your page and fill in the missing content with a recommended document for that user. Since we’re just using HTML elements, they will be styled to match the appearance of your website, and you can easily add CSS to style them even further.

Here are the three data attributes we will be using:

  • data-pfblock - unique identifier for a single recommendation block.
  • data-pfrecommend - ID or alias of a content collection (a segment on the Lytics content table) to filter documents.
  • data-pftype - the value of this attribute determines which field of the recommended document is associated with the element such as title, url, etc.

For more detailed documentation on these attributes and additional HTML examples, check out our developer docs on inline content recommendations.

Before you can use inline content recommendations, you'll need to build at least one content collection.


curl -s -XPOST "https://api.lytics.io/api/segment" \
  -H "Content-type: text/plain" \
  -H "Authorization: $LIOKEY" \
  -d '
  global CONTAINS "developers"
  path CONTAINS "blog/post"
FROM content
ALIAS developer_blog_posts
' | jq '.'

Check out our segment API docs for more info on how to create, scan, or update segments and how to construct segment definitions with SegmentQL.

Now that we’ve built a content collection, we can use it as a filter for our recommendations. This is important because there’s rarely a time where you’d want to recommend any piece of content on your website. For example, even if it matches their interests, you wouldn’t want to recommend that someone visit your Careers or About page in a marketing context.

HTML example

Alright, now that we have all the pieces, let’s put it all together. You’re going to have one wrapper element with the pfblock and pfrecommend attributes for each recommendation and then several inner elements with the pftypeattribute and values url, title, and description. We can also optionally include the image, author, or published date.

<div data-pfblock="dev_recommendation" data-pfrecommend="developer_blog_posts">
  <img data-pftype="image" alt="recommendation image">
  <h2 data-pftype="title"></h2>
  <p data-pftype="description"></p>
  <p><a data-pftype="url">Read More...</a>

As mentioned earlier, Pathfora will detect these elements and fill in the recommended document fields accordingly. Also keep in mind that adding multiple recommendation blocks that use the same content collection (same pf-recommend value) will pull recommendations from a single API call in the order that they were returned. Thus we can assure that no article will be repeated across recommendations on the same page.

That’s really all there is to it! Remember to check out our full developer documentation around inline recommendations. If you’re an existing customer and would like to try this out, reach out to our customer success team if you need assistance. If you’re new to Lytics and the idea of content recommendations interests you, reach out to our sales team to request a demo.

Based on your interests, you might also enjoy...

Explore data-driven marketing with us

Sign up for Lytics news, events and product updates straight to your inbox