Banner & MREC Ads

Programmatic Method

Creating a Banner or MREC

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

  • final String _banner_ad_unit_ID = Platform.isAndroid ? "android_banner_ad_unit_ID" : "ios_banner_ad_unit_ID";
    
    function initializeBannerAds()
    {
      // MAX automatically sizes banners to 320×50 on phones and 728×90 on tablets
      AppLovinMAX.createBanner(_banner_ad_unit_ID, AdViewPosition.bottomCenter);
    }
  • final String _mrec_ad_unit_ID = Platform.isAndroid ? "android_mrec_ad_unit_ID" : "ios_mrec_ad_unit_ID";
    
    public void initializeMRecAds()
    {
      // MAX sizes MRECs to 300×250 on phones and tablets
      AppLovinMAX.createMRec(_mrec_ad_unit_ID, AdViewPosition.bottomCenter);
    }

Displaying a Banner

To show a banner, call ShowBanner():

AppLovinMAX.showBanner(_banner_ad_unit_ID);

To hide a banner, call hideBanner():

AppLovinMAX.hideBanner(_banner_ad_unit_ID);

Widget Method

You can also render a banner or MREC directly in your widget tree:

  • final String _ad_unit_ID = Platform.isAndroid ? "android_ad_unit_ID" : "ios_ad_unit_ID";
    MaxAdView(
      adUnitId: _ad_unit_ID,
      adFormat: AdFormat.banner,
      listener: AdViewAdListener(onAdLoadedCallback: (ad) {
        ⋮
      }, onAdLoadFailedCallback: (adUnitId, error) {
        ⋮
      }, onAdClickedCallback: (ad) {
        ⋮
      }, onAdExpandedCallback: (ad) {
        ⋮
      }, onAdCollapsedCallback: (ad) {
        ⋮
      })
    )
  • final String _ad_unit_ID = Platform.isAndroid ? "android_ad_unit_ID" : "ios_ad_unit_ID";
    MaxAdView(
      adUnitId: _ad_unit_ID,
      adFormat: AdFormat.mrec,
      listener: AdViewAdListener(onAdLoadedCallback: (ad) {
        ⋮
      }, onAdLoadFailedCallback: (adUnitId, error) {
        ⋮
      }, onAdClickedCallback: (ad) {
        ⋮
      }, onAdExpandedCallback: (ad) {
        ⋮
      }, onAdCollapsedCallback: (ad) {
        ⋮
      })
    )

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.setBannerExtraParameter(banner_ad_unit_ID, "adaptive_banner", "false")

Call AppLovinMAX.getAdaptiveBannerHeightForWidth(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 an ad with the following code:

  • AppLovinMAX.showBanner(ad-unit-ID);
    AppLovinMAX.stopBannerAutoRefresh(ad-unit-ID);
  • MaxAdView(
        adUnitId: ad-unit-ID,
        adFormat: AdFormat.banner,
        isAutoRefreshEnabled: false,
        ⋮
  • AppLovinMAX.showMRec(ad-unit-ID);
    AppLovinMAX.stopMRecAutoRefresh(ad-unit-ID);
  • MaxAdView(
        adUnitId: ad-unit-ID,
        adFormat: AdFormat.mrec,
        isAutoRefreshEnabled: false,
        ⋮

Start auto-refresh for an ad with the following code:

  • AppLovinMAX.startBannerAutoRefresh(ad-unit-ID);
  • MaxAdView(
        adUnitId: ad-unit-ID,
        adFormat: AdFormat.banner,
        isAutoRefreshEnabled: true,
        ⋮
  • AppLovinMAX.startMRecAutoRefresh(ad-unit-ID);
  • MaxAdView(
        adUnitId: ad-unit-ID,
        adFormat: AdFormat.mrec,
        isAutoRefreshEnabled: true,
        ⋮