Customized implementation

Using raw API of JavaScript SDK, calling and rendering ads are available in the intended timing. Using the following explanation of API, extra implementation is needed.

Create an instance

Create an instance of controller class to manage ads. Assigning ad spots ID is necessary to have constructor.

var ad_controller = new RFP.InFeed.AdController({ adspot_id: 'MjQzOjIw' });

Sending ads request

Sending request of ads contents, and then get the information by using loadAds() method. Set down callback functions showed as argument after completed.

The First argument of callback functions is returned error object. If it works well, it returns null.

var on_ad_loaded = function(error) {
  if (error) {
    // error handling
  }

  // ...
};

ad_controller.loadAds(on_ad_loaded);

Receiving ads content

It is possible to receive ads contents which was got from server by using loadAds() by using getLoadedAds() method.

var ads = ad_controller.getLoadedAds();

A response value of getLoadedAds() is as below.

[
  {
    "title": "testAd",
    "description": "This is test ad.”
    "click_url": "https://...",
    "main_image_url": "https://...",
    "ad_id": "123",
    "displayed_advertiser": "Provided by test advertiser",
    "optout_click": "onClick=...",
    "cta_text": "Install"
  },
  ...
]

If you want to know about more details of each parameter, please refer to clause of ads parameter.

Ads display

You can show ads recieved by using getLoadedAds(). It needs to manage display processing.

Sending notification of ads impression

After showing ads, it is necessary to notice impression by using notifylmp() and passing ad_id as parameter.

var ad_id = ads[0].ad_id;
ad_controller.notifyImp(ad_id);

Additional Loading

You can load more ads contents in case of reloaded feed.

Every time calling for loadAd() method, you can get new ads content. GetLoadedAds() returns all of ads had been got so far.

It needs to use an controller instance, at first. If you keep using the only one instance, duplicate advertisements are never returned.

Example of implementation

var ad_controller = new RFP.InFeed.AdController({ adspot_id: 'MjQzOjIw' });

var on_ad_loaded = function(error) {
  if (error) {
    // Error handling
  }

  // Recieving
  var ads = ad_controller.getLoadedAds();

  ads.forEach(function(ad) {
    // showing ads according to ads content
    ShowAd(ad);

    // Notification of Ads impression
    var ad_id = ad.ad_id;
    ad_controller.notifyImp(ad_id);
  });
};

ad_controller.loadAds(on_ad_loaded);

Attention

  • Every time reading pages, get ads contents from server. Please refrain from keep using cash that you had got.
  • Ads contents you get from server are arranged to profitable order. It is better to show superior ads at the top.