horizon_select

Description

Based on the interests of the current user, returns top items from an array of content or products.

list horizon_select( array input , integer quantity , optional string engine , optional object filter_tags )

Given an input array of JSON objects, returns an array of quantity of those objects that the user is determined to be most interested in by Sailthru’s Personalization Engine, sorted by level of interest (descending). The last two parameters, engine and filter_tags, are optional ways to further refine and filter the content that is returned, and are especially powerful when used in Site Personalization Manager sections. (See Optional Parameters, below.)

The objects in the input array can contain any number of properties, but they must contain the tags property, which must be a comma-separated string or array of strings listing the tags that are relevant to this piece of content. You also may use the weight property, which can be any number to weight the value of the piece of content. For example, if you are pulling headlines from your site you may want to give a higher weight to headlines with higher numbers of pageviews.

There are many handy uses for this function, but one of the most useful involves using a Data Feed as the source for your input array. For your data feed, you can choose to use a Sailthru-generated Horizon Content Feed. In that case, Horizon will automatically assign weights to your items based on your chosen balance of pageviews and recency, as well as tags. Using a Horizon Content Feed will also allow horizon_select to exclude content that a user has previously purchased or viewed.

For more information about using Horizon Content Feeds with this function, see Horizon in Email Templates.

Example

{myfavoritefood = horizon_select
	(
		[
			{'tags':
				['trixie'],
				'name':'msd Fruit Snacks'
			},
			{'tags':
				['kong,trixie'],
				'name':'Cran-Apple Fruit Snacks'
			},
			{'tags':
				['kong'],
				'name':'Lemon Fruit Snacks'}
		],
	2)
}

After the above function is run, your two favorite fruit snacks are available in Zephyr as {myfavoritefood[0].name} and {myfavoritefood[1].name}.

Optional Parameters

You can also include the engine and filter_tags parameters to further refine the content displayed to a user. filter_tags, which lets you require certain tags or exclude certain tags from returned content, is especially useful with Site Personalization Manager: based on the context in which the page is being viewed, you can dynamically pass in variables/tags on page load in order to affect the content that is displayed, even when that content is sourced from the same section and feed.

Parameter

Description

Format/Example

engine

Specifies whether Sailthru should treat your section as supportingmedia or commerce. This distinction will be implemented in a future Sailthru product release, but a selection is required in advance if you are to begin using the next parameter, filter_tags, today.

media or commerce

filter_tags

Allows you to filter thereturned content items by specifying one or more content tags to require or exclude from the returned recommendations content. This is an object containing:

  • an array of tags
  • a flag for whether to require content with those tags (true) or exclude content with those tags (false)

{ "tags" : [kids, books, UK], "include" : true }

Your tags and include values can be dynamic values passed from your website using a vars array, per the JavaScript code specified on the Site Personalization Manager Implementation page.

You can use any variable names to send these values to the template,then include them in your filter_tags object.

For example, if you sent your tags and your include value using the variablesmytags and myinclude: 

{filter_tags =
  { "tags" : mytags,
    "include" : myinclude}
}

{content = horizon_select( content, 6, commerce, filter_tags)}

Top