Recommend trending items

You can query for items that trended over past X hours in the following way:

$p('register', {
  max: 10, // Large number requested so you can see our full range of items
  widget: 'default-widget', // name of widget
  opts: {
    "rankingKey": "click",
    "hoursBehind": 24
  },
    callback: function(resp) {
      console.log(JSON.stringify(resp, null, 2));
      console.log("// TEST.");
    }
  }
);

Note that rankingKey and hoursBehind has been set in opts. Setting hoursBehind to X will make our system return items that trended for the past X hours.

Here are the parameters specific to this endpoint, that you can set in opts:

  • rankingKey is the key used to rank the items in decreasing order. The following values are allowed for rankingKey: "click", "visible", "show", "click:visible", "click:show", and "visible:show". Keys with a ":" inside them are interpreted as ratios, so we rank in decreasing order of the ratio of the numerator to the denominator. If a value is not specified here, we return the top items but in an essentially random order.
  • lookupKey is a key with two possible values: "popular" and "click". The "popular" key restricts consideration to a shortlist of items that have received a lot of views. The "click" key restricts consideration to a shortlist of items that have received a lot of clicks. The default value of lookupKey is "click".
  • hoursBehind is the number of hours behind to go in this computation. For instance, setting this to 24 means that we will return the top items (based on rankingKey and lookupKey) over the last 24 hours.

📘

Using the feature through REST API

If you want to use the same feature using REST API, you can define the key-value pairs in opts above to the JSON body instead of nesting it into opts object. The feature is documented more on the REST API model endpoint page.