Expo

Get Started
API Reference

Admob

Expo includes support for the Google AdMob SDK for mobile advertising, including components for banner ads and imperative APIs for interstitial and rewarded video ads. expo-ads-admob is largely based of the react-native-admob module, as the documentation and questions surrounding that module may prove helpful. A simple example implementing AdMob SDK can be found here.

Platform Compatibility

Android DeviceAndroid EmulatoriOS DeviceiOS SimulatorWeb

expo install expo-ads-admob

If you're installing this in a bare React Native app, you should also follow these additional installation instructions.

For the module to attribute interactions with ads to your AdMob app properly you will need to add a googleMobileAdsAppId property to app.json under [platform].config. More info on where to find the app ID can be found in this Google Support answer. A sample valid app.json would look like:
{
  "expo": {
    "name": "Ads Showcase",
    // ...
    "android": {
      // ...
      "config": {
        // ...
        "googleMobileAdsAppId": "ca-app-pub-3940256099942544~3347511713" // sample id, replace with your own
      }
    },
    "ios": {
      // ...
      "config": {
        // ...
        "googleMobileAdsAppId": "ca-app-pub-3940256099942544~1458002511" // sample id, replace with your own
      }
    }
  }
}

import {
  AdMobBanner,
  AdMobInterstitial,
  PublisherBanner,
  AdMobRewarded,
  setTestDeviceIDAsync,
} from 'expo-ads-admob';

// Set global test device ID
await setTestDeviceIDAsync('EMULATOR');

// Display a banner
<AdMobBanner
  bannerSize="fullBanner"
  adUnitID="ca-app-pub-3940256099942544/6300978111" // Test ID, Replace with your-admob-unit-id
  servePersonalizedAds // true or false
  onDidFailToReceiveAdWithError={this.bannerError} />

// Display a DFP Publisher banner
<PublisherBanner
  bannerSize="fullBanner"
  adUnitID="ca-app-pub-3940256099942544/6300978111" // Test ID, Replace with your-admob-unit-id
  onDidFailToReceiveAdWithError={this.bannerError}
  onAdMobDispatchAppEvent={this.adMobEvent} />

// Display an interstitial
await AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712'); // Test ID, Replace with your-admob-unit-id
await AdMobInterstitial.requestAdAsync({ servePersonalizedAds: true});
await AdMobInterstitial.showAdAsync();

// Display a rewarded ad
await AdMobRewarded.setAdUnitID('ca-app-pub-3940256099942544/5224354917'); // Test ID, Replace with your-admob-unit-id
await AdMobRewarded.requestAdAsync();
await AdMobRewarded.showAdAsync();

  • Here is the full list of Test IDs
  • Ensure you never load a real production ad in an Android Emulator or iOS Simulator. Failure to do this can result in a ban from the AdMob program.
import Constants from 'expo-constants';

const testID = 'google-test-id';
const productionID = 'my-id';
// Is a real device and running in production.
const adUnitID = Constants.isDevice && !__DEV__ ? productionId : testID;

Returns whether the AdMob API is enabled on the current device. This does not check the native configuration.

Async boolean, indicating whether the AdMob API is available on the current device. Currently this resolves true on iOS and Android only.

Sets the test device ID. For simulators/emulators you can use 'EMULATOR' for the test device ID.

  • testDeviceID (string) -- Test device ID.

The default behavior of the Google Mobile Ads SDK is to serve personalized ads. If a user has consented to receive only non-personalized ads, you can configure the view to specify that only non-personalized ads should be requested. Adding servePersonalizedAds property causes non-personalized ads to be requested regardless of whether or not the user is in the EEA. The default is false — ads won't be personalized.

Prop valueDescriptionSize
bannerStandard Banner for Phones and Tablets320x50
largeBannerLarge Banner for Phones and Tablets320x100
mediumRectangleIAB Medium Rectangle for Phones and Tablets300x250
fullBannerIAB Full-Size Banner for Tablet468x60
leaderboardIAB Leaderboard for Tablets728x90
smartBannerPortraitSmart Banner for Phones and Tablets (default)Screen width x 32
smartBannerLandscapeSmart Banner for Phones and TabletsScreen width x 32
Note: There is no smartBannerPortrait and smartBannerLandscape on Android. Both prop values will map to smartBanner

Prop
onAdViewDidReceiveAd()
onDidFailToReceiveAdWithError(errorDescription: string)
onAdViewWillPresentScreen()
onAdViewWillDismissScreen()
onAdViewDidDismissScreen()
onAdViewWillLeaveApplication()

const adUnitID = Platform.select({
  // https://developers.google.com/admob/ios/test-ads
  ios: 'ca-app-pub-3940256099942544/2934735716',
  // https://developers.google.com/admob/android/test-ads
  android: 'ca-app-pub-3940256099942544/6300978111',
});

NameDescription
setAdUnitID(adUnitID)sets the AdUnit ID for all future ad requests.
requestAdAsync(options)requests an interstitial and resolves when interstitialDidLoad or interstitialDidFailToLoad event fires. An optional options object argument may specify servePersonalizedAds: true value — then ads will be personalized.
showAdAsync()shows an interstitial if it is ready and resolves when interstitialDidOpen event fires
getIsReadyAsync()resolves with boolean whether interstitial is ready to be shown

Unfortunately, events are not consistent across iOS and Android. To have one unified API, new event names are introduced for pairs that are roughly equivalent.
iOSthis libraryAndroid
interstitialDidReceiveAdinterstitialDidLoadonAdLoaded
interstitial:didFailToReceiveAdWithErrorinterstitialDidFailToLoadonAdFailedToLoad
interstitialWillPresentScreeninterstitialDidOpenonAdOpened
interstitialDidFailToPresentScreen
interstitialWillDismissScreen
interstitialDidDismissScreeninterstitialDidCloseonAdClosed
interstitialWillLeaveApplicationinterstitialWillLeaveApplicationonAdLeftApplication
Note that interstitialWillLeaveApplication and onAdLeftApplication are not exactly the same but share one event in this library.

const adUnitID = Platform.select({
  // https://developers.google.com/admob/ios/test-ads
  ios: 'ca-app-pub-3940256099942544/4411468910',
  // https://developers.google.com/admob/android/test-ads
  android: 'ca-app-pub-3940256099942544/1033173712',
});

Opens a rewarded AdMob ad.

NameDescription
setAdUnitID(adUnitID: string)sets the AdUnit ID for all future ad requests.
| requestAdAsync(options) | (async) requests a rewarded ad. An optional options object argument may specify servePersonalizedAds: true value — then ad will be personalized. | | showAdAsync() | (async) shows a rewarded if it is ready (async) |

iOSthis libraryAndroid
rewardBasedVideoAd:didRewardUserWithRewardrewardedVideoDidRewardUseronRewarded
rewardBasedVideoAdDidReceiveAdrewardedVideoDidLoadonRewardedVideoAdLoaded
rewardBasedVideoAd:didFailToLoadWithErrorrewardedVideoDidFailToLoadonRewardedVideoAdFailedToLoad
rewardBasedVideoAdDidOpenrewardedVideoDidOpenonRewardedVideoAdOpened
rewardedVideoDidCompleteonRewardedVideoCompleted
rewardBasedVideoAdDidCloserewardedVideoDidCloseonRewardedVideoAdClosed
rewardBasedVideoAdWillLeaveApplicationrewardedVideoWillLeaveApplicationonRewardedVideoAdLeftApplication
rewardBasedVideoAdDidStartPlayingrewardedVideoDidStartonRewardedVideoStarted

const adUnitID = Platform.select({
  // https://developers.google.com/admob/ios/test-ads
  ios: 'ca-app-pub-3940256099942544/1712485313',
  // https://developers.google.com/admob/android/test-ads
  android: 'ca-app-pub-3940256099942544/5224354917',
});