How does the Gravity API for Publishers work?

/recommendations

Pre-requisites

  1. Register your site with a Gravity account manager
  2. Place your Gravity beacon in your page footer
  3. Provide RSS feeds for content ingestion
  4. Receive your API placement ID from your Account Manager

Keep in Mind

  • API implementations must be validated for correctness. Please contact your account manager to schedule a trial run before going live.
  • This endpoint is only supported via client-side requests due to caching limitations. Please contact your Account Manager if a server-side request is mandatory.
  • Be sure to implement the "impression viewed callback" as described below.
  • Links to recommended articles should use the rel=nofollow attribute.

 

GET http://api.gravity.com/v2/recommendations

This is Gravity’s core recommendation API. It returns a set of personalized stories for the user indicated by the userGuid parameter. Personalized stories are determined by the similarity between the user’s interest graph and the interest graph of available stories from the content source (usually the website using the API).

ParameterDescription
placement
required

A 4 digit number representing the placement configuration. Provided by your Gravity Account Manager.

Example Value: 1234

userGuid
required

The 32 character hexadecimal GUID of the user for whom to return the results. This value is stored by Gravity's beacon code in your site's cookie under the name "grvinsights". If the beacon code has not yet been stored, you may send the empty string once per user.

Warning: Be sure to send the userguid when it is available, or else personalization will not occur.

Example Value: 85cca408336572e970f89951ad7ea11c

url
required

Results will not include this URL and impressions for the API call are logged against this particular URL for reporting purposes.

Example Value: http://www.gravity.com/blog/big-datas-next-evolution-relevancy/

page
optional

The page of results to return. Results from previous pages will not be returned. The page count starts at "0" which is the default value if no page parameter is present. Subsequent pages can be retrieved by incrementing the page parameter. This parameter can be used to implement an "infinite scroll" feature where a user is continually shown new recommendations as they scroll down.

Example Value: 0

imageSize
optional

Specify the width of an image to return in the results if an image is available. There are 5 valid image sizes: 100, 200, 300, 400 or the original size. If a mid-range value is provided such as 150 the next largest size will be returned, in the case of 150 that would be 200. To return the original size, omit this parameter.

Example Value: 400

Our sample JS code can serve as a template:

Impression Viewed

The Impression Viewed Callback is a unique URL returned for each set of API results. The callback should be used to tell Gravity when a user has actually seen the recommendations being returned. When the user scrolls the rendered recommendations into view, please issue a request to the url returned as impressionViewed.callback. This is separate from the regular impression that is logged via a beacon on page load regardless of if the user saw the recommendations or not. By using the Impression Viewed Callback, Gravity algorithms can do further performance optimization and metrics such as optimizing based on impressions viewed.

Example Request
GET http://api.gravity.com/v2/recommendations?placement=2635&userguid=580e85767338104bbcdaaa99549de5f7&url=http://gravity.com/blog
Example Response
{
  "payload":{
    "articles":[
      {
        "title":"The World's Most Powerful Female Entrepreneurs of 2014",
        "clickUrl":"http://api.gravity.com/302/redirect?grcc2=8637c3888cc14dcc015436ff18a56035%7E1413856029761%7Ebc210cd6294b0d20913c259869298190%7EABC123456789ABCDEFGHIJKLMNOPQRST%7E1413855135367%7E598%7E2%7E0%7E0%7E0%7E-1%7E-1%7E-1%7E34%7E2%7E38%7EH4sIAAAAAAAAAIVQvW7cMAx-lXrIKIEUJZnKFhQo0DlI10I-03cubMuQnDOy6NmrCzJ0K0nwn8RH3o5jf6KXJ_OjyTXH-3x86EtaWzQs6VoVWrTWgrOB2Aff28D19u_QeZ56SnmQ8jVX5kNKs7LOy8e83SWX1EIDaJsB9_C5qeMm6kx5GYtaUznUnk7J0_uiJlnjIkq2I8ueZZP3XFSa1NeGajy5Wl0DYlxfx8mh643YaCw76j2GiQY_IAbDxPz_hlofkH-Oz-1YCoHQBHYe2IPt4fclrnucr9uj7pnJeW-tIx-YwDUg8MkKa9NN3l67t62tG7-9HrE9oiOE7pds80U6BuqIdAjWdgqRtfXEn9kAJmD3_aVGsuMwNqwA4MyATMa5iGza70HGoSKwRtKGQGMPtfy5oIr7DGh6vec06mu-1ykuReqD_gLqYjdX4AEAAA",
        "image":"http://specials-images.forbesimg.com/imageserve/bef9b50280283e17b68e2b5597bfc2b7/0x600.jpg?fit=scale&background=000000",
        "type":"organic",
        "publishTimestamp":"1401364410000",
        "summary":"From fresh faces to billionaires, entrepreneurs make up 20% of this year’s Most Powerful Women list. Their impact reaches business, media and philanthropy, and over the last year, many have leveraged their top-tier status for the greater good of social causes. These Power Women are setting an stron",
        "author":"",
        "displayUrl":"http://www.forbes.com/sites/emilyinverso/2014/05/28/the-worlds-most-powerful-female-entrepreneurs-of-2014/"
      },
      {
        "title":"Tesla's Clever Patent Move Is Already Paying Off",
        "clickUrl":"http://api.gravity.com/302/redirect?grcc2=31943d696fd54a068975c02ddf78482b%7E1413856029761%7Ebc210cd6294b0d20913c259869298190%7EABC123456789ABCDEFGHIJKLMNOPQRST%7E1413855135367%7E598%7E2%7E0%7E0%7E0%7E-1%7E-1%7E-1%7E34%7E2%7E38%7EH4sIAAAAAAAAAIVQuW7DMAz9lXroKIGUqKtbUKBA5yBdA9mWj8KRDUtJ0EXfXqXo0K0k8R54PILglPP2LA_P4q3GuPvbnL94t15q1i7rWBhpSYRoyJAjq0BpKtNf0f1-59N1GOY45jVua8q_egFIlUBXwAfkkBbPNp9DzCxdt7B3k9_HsLOUfZ7XeI5npQCMID7ly1KElqoU5WwRyhSnQie0bgVRHwza1kKnlfBg_QB68P8PlJLmHN77F4YknZMonFUarAYycO78ZfPzGB99ba1UWhMpqZ2VoOohUB0Lw1K5xunYnGJd1z8d6_UhNRKh-Qhx7kJjQTZScueIGoZoef2i_ak6EA6b10Pxkvq2D-QBQIkWrRRKebRCOw2hbwuC5Si5kMDRQEmfHTK_zYDC8G1fez7utzL4JYXysG9ln_yFyQEAAA",
        "image":"http://i.huffpost.com/gen/1631468/original.jpg",
        "type":"organic",
        "publishTimestamp":"1403109011000",
        "summary":"Tesla may already be reaping the rewards of freeing up its patents. Four days after CEO Elon Musk offered most of his company’s patents to rivals in hopes of cultivating a bigger electric car market, Nissan and BMW are “keen on talks” to cooperate on charging networks, the Financial Times reported ",
        "author":"Alexander C. Kaufman",
        "displayUrl":"http://www.huffingtonpost.com/2014/06/16/tesla-patent-supercharger-station_n_5500724.html"
      }
    ],
    "impressionViewed":{
      "hash":"a34dbde4a00052b183255a1826960edb",
      "callback":"http://api.gravity.com/v0/site/bc210cd6294b0d20913c259869298190/user/bc210cd6294b0d20913c259869298190/impressionViewed?placement=2635&userguid=ABC123456789ABCDEFGHIJKLMNOPQRST&url=http://gravity.com/blog&ih=a34dbde4a00052b183255a1826960edb&ct=1413856030335"
    }
  },
  "status":{
    "httpCode":200,
    "message":"OK",
    "executionTime":"658 milliseconds",
    "executionMillis":658
  }
}
            
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

Powered by Zendesk