Request Stand-Alone Ads via the Web SDK

This guide explains how to integrate stand-alone ads into your website.
It requires an installed FeedAd SDK and therefore access to the feedad object. Read the installation guide if you have not initialized the SDK, yet.

Implementation

All asynchronous operations happening in the Web SDK are implemented as Promises and can be observed as such.

You can find a detailed example integration inside the example project's 'standalone' folder.

The ad request can be separated into four steps:

1. Initialize the SDK

You have to initialize the FeedAd SDK before requesting any ad.

feedad.init("your-web-client-token");

2. Request a placement

feedad.requestStandaloneAd("your-placement-id")
      .then(function (adResponse) { 
      });

Placement ID?

You can choose placement IDs yourself. A placement ID should be named after the ad position inside your product. For example, if you want to display an ad inside a list of news articles, you could name it "ad-news-overview".
A placement ID may consist of lowercase a-z, 0-9, - and _. You do not have to manually create the placement IDs before using them. Just specify them within the code, and they will appear in the FeedAd admin panel after the first request. Learn more about Placement IDs and how they are grouped to play the same Creative

3. Add the ad to your page

The element holding the ad will be available through the adResponse.createAdContainer() property. You can add the element to your DOM to show the ad.

feedad.requestStandaloneAd("your-placement-id")
      .then(function (adResponse) {
          // the ad element
          var adElement = adResponse.createAdContainer();

          //insert the ad element
          var adContainer = document.getElementById("some-element");
          adContainer.appendChild(adElement);
      });

4. Listen for the ad completion

Once the ad element becomes visible, it will automatically start playing its creative. When the player has successfully played one creative, it will stay blank forever after. You should listen for the ad response's promise to be fulfilled and display your content afterwards.

feedad.requestStandaloneAd("your-placement-id")
      .then(function (adResponse) {
          // the ad element
          var adElement = adResponse.createAdContainer();

          //insert the ad element
          var adContainer = document.getElementById("some-element");
          adContainer.appendChild(adElement);

          // wait for the ad to finish
          return adResponse.promise;
      })
      .then(function () {
          // the ad was played
          displayContent();
      })
      .catch(function (e) {
          // there was no ad available or the playback failed
          console.log("error requesting ad", e);
          displayContent();
      });

You can find more information about the error callback within the Feed Ad integration docs.

Test your integration

Once you've setup all ad placements it is time to test the ad playback and error handling strategies.

Ad Request Options

You can provide additional options for the ad request:

feedad.requestStandaloneAd("your-placement-id", {
    scaleMode: "parent_width",
    connectionType: "3g"
});

The following keys and values are accepted by the options object:

Key Value
scaleMode
"parent_width" (default)
The player will have the same width as its parent element. The height will scale based on the creative's aspect ratio.
"parent_height"
The player will have the same height as its parent element. The width will scale based on the creative's aspect ratio.
"creative"
The ad player will size itself to the dimensions of the creative. You'll have to apply your own sizing.
connectionType "unknown" (default) | "wifi" | "2g" | "3g" | "4g"
Specifies the type of the connection so the ad server may filter out creatives with high bandwidth volume.