Integrating with recommender

Background

This article outlines how to integrate recommendations with your web pages.

Funnelback’s recommender returns a set of recommendations given a URL. These recommendations are intended to be embedded into a content page to provide suggestions for other related pages. This can be used for functionality such as people that were interested in this thing are also interested in these things.

Recommendations must be configured and enabled on the collection that is being queried.

Example: JQuery function to integrate with recommender

The example JQuery function below fetches and inject recommendations for the current URL Funnelback’s recommender API and injects them into an element with an ID of similar-items. Adjust the Funnelback server, collection ID, num recommendations and mode as appropriate.

The current page URL (document.location.href) must exactly match the URL that was indexed by Funnelback for any matching recommendations to be returned.

Before you start it is a good idea to access the similarItems.json URL directly to verify that recommendations are being returned.

jQuery(document).ready(function () {
	jQuery.ajax({
	    type: 'GET',
	    url: 'http://<FUNNELBACK-SERVER>/s/recommender/similarItems.json?seedItem='+document.location.href+'&collection=<COLLECTION-ID>&maxRecommendations=<NUM-RECOMMENDATIONS>&source=<MODE>',
	    data: { get_param: 'value' },
	    dataType: 'jsonp',
	    success: function (data) {
	        $.recommendations.each(data, function(index, element) {
	            $('#similar-items').append('<div><a href="'+element.itemID+'">'+element.title+'</a> ('+element.metaData.type+')</div>');
	        });
	    }
	});
});

See also