Banner Ads

Programmatic Method

Creating a Banner

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

const BANNER_AD_UNIT_ID = Platform.select({
  android: 'android_banner_ad_unit_ID',
  ios: 'ios_banner_ad_unit_ID',
});

function initializeBannerAds()
{
  // Banners are automatically sized to 320x50 on phones and 728x90 on tablets
  // You may use the utility method `AppLovinMAX.isTablet()` to help with view sizing adjustments
  AppLovinMAX.createBanner(BANNER_AD_UNIT_ID, AppLovinMAX.AdViewPosition.BOTTOM_CENTER);

  // Set background or background color for banners to be fully functional
  // In this case we are setting it to black - PLEASE USE HEX STRINGS ONLY
  AppLovinMAX.setBannerBackgroundColor(BANNER_AD_UNIT_ID, '#000000');
}

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);

Native UI Component Method

You can also render banners directly in your DOM as a native UI component, as in the following example:

<AppLovinMAX.AdView adUnitId={banner_ad_unit_ID}
                    adFormat={AppLovinMAX.AdFormat.BANNER}
                    style={styles.banner}
                    onAdLoaded={(adInfo) => {
                      console.log('Banner ad loaded from ' + adInfo.networkName);
                    }}
                    onAdLoadFailed={(errorInfo) => {
                      console.log('Banner ad failed to load with error code ' + errorInfo.code + ' and message: ' + errorInfo.message);
                    }}
                    onAdClicked={(adInfo) => {
                      console.log('Banner ad clicked');
                    }}
                    onAdExpanded={(adInfo) => {
                      console.log('Banner ad expanded')
                    }}
                    onAdCollapsed={(adInfo) => {
                      console.log('Banner ad collapsed')
                    }}
                    onAdRevenuePaid={(adInfo) => {
                      console.log('Banner ad revenue paid: ' + adInfo.revenue);
                    }}/>

⋮

// This example anchors the bottom of the banner to the bottom of the screen
const styles = StyleSheet.create({
  banner: {
    // Set background color for banners to be fully functional
    backgroundColor: '#000000',
    position: 'absolute',
    width: '100%',
    height: 'auto', //  Let AdView define based on device type and adaptive mode
    bottom:  Platform.select({
      ios: 36, // For bottom safe area
      android: 0,
    })
  }
});

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. Banners from ad networks that support adaptive banners are adaptive by default starting in plugin version 2.3.0. To disable adaptive banners, set an extra flag as in the following examples:

  • AppLovinMAX.SetBannerExtraParameter(banner_ad_unit_ID, "adaptive_banner", "false");
  • <AppLovinMAX.AdView adUnitId={banner_ad_unit_ID}
                        adFormat={AppLovinMAX.AdFormat.BANNER}
                        adaptiveBannerEnabled={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 a banner ad or want to manually refresh. Stop auto-refresh for a banner ad with the following code:

  • AppLovinMAX.showBanner(banner_ad_unit_ID);
    AppLovinMAX.stopBannerAutoRefresh(banner_ad_unit_ID);
  • <AppLovinMAX.AdView adUnitId={banner_ad_unit_ID}
                        adFormat={AppLovinMAX.AdFormat.BANNER}
                        autoRefresh={false} />

Start auto-refresh for a banner ad with the following code:

  • AppLovinMAX.startBannerAutoRefresh(banner_ad_unit_ID);
  • <AppLovinMAX.AdView adUnitId={banner_ad_unit_ID}
                        adFormat={AppLovinMAX.AdFormat.BANNER}
                        autoRefresh={true} />