Banner ads

This section provides details and examples of how to configure, load, and display a banner ad. You can display the ad when it loads, or on some other specific event; for example, when the user clicks a button.

Set up and load a banner ad

Before you can display an ad on your app you first need to set the required configuration items, and then pass the ad placement ID to the load method.

For example:

public class MainScript : MonoBehaviour {

    private SABannerAd banner = null;

    void Start () {

        // Initialise the SDK (Skip this if you already initialised it elsewhere...)
        AwesomeAds.init(true); // In production usages set logging parameter to false

        // Create a new banner
        banner = SABannerAd.createInstance();

        // Set configuration to production
        banner.setConfigurationProduction();

        // Enable test ads
        banner.enableTestMode();

        // Start loading ad data for a placement
        banner.load(30471);
    }
  }

Configuration Methods

Parameter Default value Configure Using
Configuration Production setConfigurationProduction()
Test mode Disabled enableTestMode(), disableTestMode()
Background Color Gray setColorTransparent(), setColorGrey()
Size 320x50 setSize_300_50(), setSize_320_50(), setSize_728_90(), setSize_300_250()
Position Bottom setPositionBottom(), setPositionTop()

Aditional load parameters

You can also send additional options during the load() call as well as an optional OpenRTB partner ID. Both parameters are optional.

var options = new Dictionary<string, string>
  {
    ["key"] = "value"
  };

string openRTBPartnerId = "1234";
banner.load(30471, openRTBPartnerId, options);

Display the banner ad

To display the ad, call play, using either the adLoaded callback or the hasAdAvailable method:

  • Use the adLoaded callback to display the ad as soon as it is loaded. Add the callback before you call the load method:

    For example:

    using tv.superawesome.sdk.publisher;
    
    public class MainScript : MonoBehaviour {
    
      private SABannerAd banner = null;
    
      void Start() {
    
          // Initialise the SDK (Skip this if you already initialised it elsewhere...)
          AwesomeAds.init(true); // In production usages set logging parameter to false
    
          // Create a new banner ad
          banner = SABannerAd.createInstance();
    
          // Add a callback
          banner.setCallback((placementId, evt) => {
    
              // When the ad loads, play it directly
              if (evt == SAEvent.adLoaded) {
                  banner.play();
              }
          });
    
          // Start the loading process
          banner.load(30471);
      }
    }
    
  • Use the hasAdAvailable method in scenarios where you want to display the ad on another event, such as when the user clicks a button in the app:

    For example:

    using tv.superawesome.sdk.publisher;
    
    public class MainScript : MonoBehaviour {
    
      private SABannerAd banner = null;
    
      void Start() {
    
          // Initialise the SDK (Skip this if you already initialised it elsewhere...)
          AwesomeAds.init(true); // In production usages set logging parameter to false
    
          // Create a new banner ad
          banner = SABannerAd.createInstance();
    
          // Load the ad
          banner.load(30471);
    
      }
    
      public void onClick() {
    
        // Checks if an ad is loaded
        if (banner.hasAdAvailable()) {
    
            // Optional configuration
            banner.setSize_320_50();
            banner.setColorGray();
            banner.setPositionTop();
    
            // Display the ad
            banner.play();
          }
       }
    }