Banner Integration for Unity

Banner ads usually appear at the top or bottom of your app’s screen. Adding one to your app takes just a few lines of code.

Starting with the 5.8.0 release of the MoPub SDK, you can specify a desired maximum ad size, and the MoPub SDK will request an ad for that size. To use that feature, ensure you are using the new ad request API as detailed below.

If your game is distributed on both iOS and Android, you only need to import the plugin once, but you must create different ad units for each platform:

#if UNITY_IOS
    adUnitId = "YOUR_IOS_AD_UNIT_ID";
#elif UNITY_ANDROID 
    adUnitId = "YOUR_ANDROID_AD_UNIT_ID";
#endif
    MoPub.RequestBanner(adUnitId, position, maxAdSize);

Integration

  1. Request a banner. Note that the MoPub.CreateBanner(adUnitId, position) API has been deprecated as of v5.8.0 of the MoPub Unity SDK.

      MoPub.RequestBanner(bannerAdUnit, position, maxAdSize);
    

    Below is the complete list of recognized maximum ad sizes:

     Width300Height50
     Width300Height250
     Width320Height50
     Width336Height280
     Width468Height60
     Width728Height90
     Width970Height90
     Width970Height250
     ScreenWidthHeight50
     ScreenWidthHeight90
     ScreenWidthHeight250
     ScreenWidthHeight280
    
  2. Show or hide the banner (this is optional; the banner is shown by default):

      MoPub.ShowBanner (bannerAdUnit, true);   // shows the banner
    
      MoPub.ShowBanner (bannerAdUnit, false);  // hides the banner
    
  3. Destroy the banner:

      MoPub.DestroyBanner (bannerAdUnit);
    

Best Practices

  • Only create a banner ad view when you display it to the user.
  • If the user navigates from a screen with a banner on it to a screen that does not have a banner, destroy or hide the banner.
  • To be informed of the ad’s lifecycle events, visit the MoPubManager class for the complete list of ad lifecycle callbacks that you may subscribe to.

Last updated October 18, 2019

TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.

© 2019 MoPub (a division of Twitter, Inc.)