Banner & MREC Ads

Programmatic Method

Creating a Banner

The following code shows you how to load a banner or MREC by using your Ad Unit ID and desired ad position (MAX will size the ad for you automatically):

  • const BANNER_AD_UNIT_IDS = {
      "android" : "android_banner_ad_unit_ID",
      "ios" : "ios_banner_ad_unit_ID"
    }
    
    func initializeBannerAds:
      var platform = OS.get_name().to_lower() # "android", "ios", etc.
      var ad_unit_id = adUnitsDict.get(platform)
    
      # MAX automatically sizes banners to 320×50 on phones and 728×90 on tablets
      AppLovinMAX.create_banner(ad_unit_id, AppLovinMAX.BannerPosition.BOTTOM_CENTER)
  • const MREC_AD_UNIT_IDS = {
      "android" : "android_mrec_ad_unit_ID",
      "ios" : "ios_mrec_ad_unit_ID"
    }
    
    func initializeMRecAds:
      var platform = OS.get_name().to_lower() # "android", "ios", etc.
      var ad_unit_id = adUnitsDict.get(platform)
    
      # MRECs are sized to 300x250 on phones and tablets
      AppLovinMAX.create_mrec(ad_unit_id, AppLovinMAX.AdViewPosition.BOTTOM_CENTER)

Displaying a Banner or MREC

To show a banner or MREC, make the following call:

  • AppLovinMAX.show_banner(ad_unit_ID);
  • AppLovinMAX.show_mrec(ad_unit_ID);

To hide a banner or MREC, make the following call:

  • AppLovAppLovinMAX.hide_banner(ad_unit_ID);
  • AppLovAppLovinMAX.hide_mrec(ad_unit_ID);

Adaptive Banners

Only Google bidding and Google AdMob, and Google Ad Manager support adaptive banners. MAX sizes banners from other networks normally.

Google recommends that developers include a 50px padding between the banner placement and the app content to reduce the likelihood of accidental clicks. Refer to Google’s “About Confirmed Click” policy for more information and best practices.

Adaptive banners are responsive banners with heights that derive from the device type and the width of the banner. To disable adaptive banners, set an extra flag as in the following example:

AppLovinMAX.set_banner_extra_parameter(banner_ad_unit_ID, "adaptive_banner", "false")

Call AppLovinMAX.get_adaptive_banner_height_for_width(width) to get the banner height, and then adjust your content accordingly.

Stopping and Starting Auto-Refresh

There may be cases when you would like to stop auto-refresh, for instance, when you hide an ad or want to manually refresh. Stop auto-refresh for a banner or MREC ad with the following call:

AppLovinMAX.stop_banner_auto_refresh(ad-unit-ID);

Start auto-refresh for a banner or MREC ad with the following call:

AppLovinMAX.start_banner_auto_refresh(ad-unit-ID);