Google Mobile Ads React Native API

The @google/mobile-ads module provides the core TypeScript interfaces, classes, and top-level functions for integrating Google Mobile Ads into React Native applications.

Overview


Type Aliases
AdapterState
Represents the possible initialization states of a mediation adapter.
AdChoicesPlacement
Positions for the AdChoices icon in the ad view.
AdFormat
Format of the ad being requested.
AdInspectorError
Error information about why the ad inspector failed.
AdInspectorErrorCode
Errors affecting the opening or operation of the ad inspector.
AdOrientation
Orientation options for inline adaptive and large anchored adaptive banner ads.
AdSize
Represents the dimensions of an ad.
AgeRestrictedTreatment
Defines the age-restricted treatment options for ad requests.
ConsentStatus
Consent status values.
DebugGeography
Debug values for testing geography.
FormErrorCode
Represents error codes for User Messaging Platform (UMP) form operation failures.
FullScreenContentErrorCode
LoadAdErrorCode
Represents error codes for ad load operation failures.
MaxAdContentRating
Defines the maximum ad content rating for the app, classifying the types of ads that can be shown.
NativeAdAssetNames
Names used to identify standard native ad assets.
NativeAdType
Identifies the format of a loaded native ad.
NativeMediaAspectRatio
Preferences for the aspect ratio of returned native ad media.
OnAdInspectorClosedListener
Interface definition for a callback to be invoked when the ad inspector UI closes.
PrecisionType
The precision of the reported ad value.
PrivacyOptionsRequirementStatus
Privacy options requirement status.
PublisherPrivacyPersonalizationState
Indicates the Publisher privacy treatment personalization states.
ResizeMode
Options to customize the resize mode of image content in NativeAdMediaView.
ResolvedAdSize
Represents the final resolved state of an ad size after an ad has loaded.
SwipeGestureDirection
Directions for custom click swipe gestures.
Variables
AdSize
Predefined ad sizes and helper methods for creating adaptive and custom sizes.
Functions
canRequestAds
Checks whether the current consent status permits you to request ads.
getConsentStatus
Gets the user's current consent status.
getInitializationStatus
Gets the SDK initialization status.
getPrivacyOptionsRequirementStatus
Checks whether a privacy options entry point is required for your app.
getRequestConfiguration
Gets the global request configuration.
initialize
Initializes the Google Mobile Ads SDK.
isConsentFormAvailable
Checks whether a consent form is available.
loadAndShowConsentFormIfRequired
Loads a consent form and presents it to the user if their current consent status requires it (e.g., status is REQUIRED).
openAdInspector
Opens the Google Mobile Ads SDK Ad Inspector overlay.
openDebugMenu
Opens the debug menu.
parseLoadAdError
Parses a native error thrown during ad load and wraps it in a LoadAdError.
requestConsentInfoUpdate
Requests a consent information update.
reset
Clears all consent state from persistent storage.
setPublisherFirstPartyIdEnabled
Controls whether the publisher first-party ID is enabled.
setRequestConfiguration
Sets the global request configuration for compliance and targeting.
setUserControlledAppVolume
Sets the user-controlled application's audio volume.
setUserMutedApp
Sets whether the application is muted.
showPrivacyOptionsForm
Shows the privacy options form.

Type Aliases


AdapterState

AdapterState: typeof AdapterState[keyof typeof AdapterState]
Represents the possible initialization states of a mediation adapter.
Properties
NOT_READY
Indicates that the mediation adapter isn't yet initialized or failed to initialize.
READY
Indicates that the mediation adapter is successfully initialized and ready to serve ads.

AdChoicesPlacement

AdChoicesPlacement: typeof AdChoicesPlacement[keyof typeof AdChoicesPlacement]
Positions for the AdChoices icon in the ad view.
Properties
BOTTOM_LEFT
Bottom-left corner of the ad.
BOTTOM_RIGHT
Bottom-right corner of the ad.
TOP_LEFT
Top-left corner of the ad.
TOP_RIGHT
Top-right corner of the ad.

AdFormat

AdFormat: typeof AdFormat[keyof typeof AdFormat]
Format of the ad being requested.
Properties
APP_OPEN
App Open ad format.
BANNER
Banner ad format.
INTERSTITIAL
Interstitial ad format.
NATIVE
Native ad format.
REWARDED
Rewarded ad format.
REWARDED_INTERSTITIAL
Rewarded Interstitial ad format.

AdInspectorError

AdInspectorError: BaseError<AdInspectorErrorCode>
Error information about why the ad inspector failed.

AdInspectorErrorCode

AdInspectorErrorCode: typeof AdInspectorErrorCode[keyof typeof AdInspectorErrorCode]
Errors affecting the opening or operation of the ad inspector.
Properties
ALREADY_OPEN
Ad inspector cannot be opened because it's already open.
FAILED_TO_LOAD
Ad inspector failed to load.
INTERNAL_ERROR
Ad inspector had an internal error.
NOT_IN_TEST_MODE
Ad inspector cannot be opened because the device isn't in test mode.

AdOrientation

AdOrientation: typeof AdOrientation[keyof typeof AdOrientation]
Orientation options for inline adaptive and large anchored adaptive banner ads.
Properties
CURRENT
LANDSCAPE
PORTRAIT

AdSize

Represents the dimensions of an ad.

May be one of a predefined set of sizes (e.g. AdSize.LARGE_BANNER), or an adaptive size.

AgeRestrictedTreatment

AgeRestrictedTreatment: typeof AgeRestrictedTreatment[keyof typeof AgeRestrictedTreatment]
Defines the age-restricted treatment options for ad requests.
Properties
CHILD
Indicates that ad requests should receive CHILD age treatment.
TEEN
Indicates that ad requests should receive TEEN age treatment.
UNSPECIFIED
Indicates that no specific age restricted treatment signal applies to the ad request.

ConsentStatus

ConsentStatus: typeof ConsentStatus[keyof typeof ConsentStatus]
Consent status values.
Properties
NOT_REQUIRED
Consent not required.
OBTAINED
User consent obtained, personalized vs non-personalized undefined.
REQUIRED
User consent required but not yet obtained.
UNKNOWN
Unknown consent status.

DebugGeography

DebugGeography: typeof DebugGeography[keyof typeof DebugGeography]
Debug values for testing geography.
Properties
DISABLED
Debug geography disabled for debug devices.
EEA
Geography appears as in EEA for debug devices.
OTHER
Geography appears as in a region with no regulation in force for debug device.
REGULATED_US_STATE
Geography appears as in a regulated US State for debug devices.

FormErrorCode

FormErrorCode: typeof FormErrorCode[keyof typeof FormErrorCode]
Represents error codes for User Messaging Platform (UMP) form operation failures.
Properties
ALREADY_USED
The consent form has already been used.
INTERNAL_ERROR
Something happened internally within the SDK.
INVALID_OPERATION
The operation was invalid.
NETWORK_ERROR
The form operation failed due to network connectivity.
TIMEOUT
The form operation timed out.
UNAVAILABLE
No consent form is available.
UNKNOWN
The error code could not be mapped to a known error code.

FullScreenContentErrorCode

FullScreenContentErrorCode: typeof FullScreenContentErrorCode[keyof typeof FullScreenContentErrorCode]
Properties
AD_ALREADY_USED
The ad has already been shown.
AD_NOT_READY
The ad isn't ready to be shown.
AD_TOO_LARGE
Ad is too large for the scene (iOS only).
APP_NOT_FOREGROUND
The app isn't in the foreground.
INTERNAL_ERROR
Something happened internally; for instance, an exception occurred when preparing to show ad content.
MEDIATION_ERROR
The mediation adapter failed to show the ad. See FullScreenContentError.mediationAdError for the underlying cause.
UNKNOWN
The error code could not be mapped to a known error code.

LoadAdErrorCode

LoadAdErrorCode: typeof LoadAdErrorCode[keyof typeof LoadAdErrorCode]
Represents error codes for ad load operation failures.
Properties
AD_ALREADY_USED
The ad response has already been used to load an ad.
APP_ID_MISSING
The ad request wasn't made because the Application ID is missing.
CANCELLED
The ad request was cancelled (Android only).
INTERNAL_ERROR
Something happened internally within the SDK.
INVALID_REQUEST
The ad request was invalid; for instance, the ad unit ID was incorrect.
INVALID_RESPONSE
The server-to-server ad response is invalid. For example, there is no request ID in the ad response.
MEDIATION_ERROR
The mediation adapter could not be found, or failed to perform the ad request.
NETWORK_ERROR
The ad request was unsuccessful due to network connectivity.
NO_FILL
The ad request was successful, but no ad was returned due to lack of ad inventory.
TIMEOUT
The ad request timed out.
UNKNOWN
The error code could not be mapped to a known error code.

MaxAdContentRating

MaxAdContentRating: typeof MaxAdContentRating[keyof typeof MaxAdContentRating]
Defines the maximum ad content rating for the app, classifying the types of ads that can be shown.
Properties
G
Content suitable for general audiences, including families and children.
MA
Content suitable only for mature audiences.
PG
Content suitable for most audiences with parental guidance.
T
Content suitable for teen and older audiences.
UNSPECIFIED
No specified content rating.

NativeAdAssetNames

NativeAdAssetNames: typeof NativeAdAssetNames[keyof typeof NativeAdAssetNames]
Names used to identify standard native ad assets.
Properties
ADCHOICES_CONTAINER_VIEW
The container for the AdChoices overlay.
ADVERTISER
The name of the advertiser.
BODY
The main body text of the ad.
CALL_TO_ACTION
The call-to-action text for the ad (for example, "Install" or "Learn More").
HEADLINE
The headline or title of the ad.
ICON
The icon image for the ad.
MEDIA_CONTENT
The primary media content of the ad (image or video).
PRICE
The price of the advertised app or product.
STAR_RATING
The star rating for the advertised app or product.
STORE
The store name.

NativeAdType

NativeAdType: typeof NativeAdType[keyof typeof NativeAdType]
Identifies the format of a loaded native ad.
Properties
BANNER
Banner ad.
CUSTOM_NATIVE
Custom native format ad.
NATIVE
Native ad.

NativeMediaAspectRatio

NativeMediaAspectRatio: typeof NativeMediaAspectRatio[keyof typeof NativeMediaAspectRatio]
Preferences for the aspect ratio of returned native ad media.
Properties
ANY
No preference for the aspect ratio of the returned native ad media.
LANDSCAPE
Request a landscape aspect ratio for the returned native ad media.
PORTRAIT
Request a portrait aspect ratio for the returned native ad media.
SQUARE
Request a square aspect ratio for the returned native ad media.
UNKNOWN
Aspect ratio is unknown.

OnAdInspectorClosedListener

OnAdInspectorClosedListener: ((error?) => void)
Interface definition for a callback to be invoked when the ad inspector UI closes.

PrecisionType

PrecisionType: typeof PrecisionType[keyof typeof PrecisionType]
The precision of the reported ad value.
Properties
ESTIMATED
An ad value estimated from aggregated data.
PRECISE
The precise value paid for this ad.
PUBLISHER_PROVIDED
A publisher-provided ad value, such as manual CPMs in a mediation group.
UNKNOWN
An ad value with unknown precision.

PrivacyOptionsRequirementStatus

PrivacyOptionsRequirementStatus: typeof PrivacyOptionsRequirementStatus[keyof typeof PrivacyOptionsRequirementStatus]
Privacy options requirement status.
Properties
NOT_REQUIRED
Privacy options entry point isn't required.
REQUIRED
Privacy options entry point is required.
UNKNOWN
Privacy options requirement status is unknown.

PublisherPrivacyPersonalizationState

PublisherPrivacyPersonalizationState: typeof PublisherPrivacyPersonalizationState[keyof typeof PublisherPrivacyPersonalizationState]
Indicates the Publisher privacy treatment personalization states.
Properties
DEFAULT
Indicates that the ad request should receive the default publisher privacy treatment.
DISABLED
Indicates that the ad request should receive the non-personalized publisher privacy treatment.
ENABLED
Indicates that the ad request should receive the personalized publisher privacy treatment.

ResizeMode

ResizeMode: typeof ResizeMode[keyof typeof ResizeMode]
Options to customize the resize mode of image content in NativeAdMediaView.
Properties
CONTAIN
Scale uniformly to fit within the view.

Image height and width are scaled together so that each dimension is less than or equal to the corresponding dimension of the view. The image is scaled to fit inside of the view without distorting its aspect ratio or being cropped.
COVER
Scale uniformly to cover the view.

Image height and width are scaled together so that each dimension is equal to or larger than the corresponding dimension of the view. The image is cropped to fit the view without distorting its aspect ratio.
STRETCH
Scale width and height independently to fill the view.

Image height and width are scaled separately to match the dimensions of the view. The image is scaled to fill the view completely without cropping, however, the aspect ratio of the image isn't maintained.

ResolvedAdSize

ResolvedAdSize: FixedAdSize | FluidAdSize
Represents the final resolved state of an ad size after an ad has loaded.

For most ads, this resolves to a FixedAdSize with exact width and height dimensions. For dynamically sized banner ads, this resolves to a FluidAdSize where dimensions are managed by the view hierarchy.

SwipeGestureDirection

SwipeGestureDirection: typeof SwipeGestureDirection[keyof typeof SwipeGestureDirection]
Directions for custom click swipe gestures.
Properties
DOWN
Swipe down.
LEFT
Swipe left.
RIGHT
Swipe right.
UP
Swipe up.

Variables


AdSize

AdSize: {
  BANNER: FixedAdSize;
  custom: ((width, height) => FixedAdSize);
  FLUID: FluidAdSize;
  FULL_BANNER: FixedAdSize;
  getCurrentOrientationInlineAdaptiveBannerAdSize: ((width) => InlineAdaptiveAdSize);
  getInlineAdaptiveBannerAdSize: ((width, maxHeight) => InlineAdaptiveAdSize);
  getLandscapeInlineAdaptiveBannerAdSize: ((width) => InlineAdaptiveAdSize);
  getLargeAnchoredAdaptiveBannerAdSize: ((width) => Promise<LargeAnchoredAdaptiveAdSize>);
  getLargeLandscapeAnchoredAdaptiveBannerAdSize: ((width) => Promise<LargeAnchoredAdaptiveAdSize>);
  getLargePortraitAnchoredAdaptiveBannerAdSize: ((width) => Promise<LargeAnchoredAdaptiveAdSize>);
  getPortraitInlineAdaptiveBannerAdSize: ((width) => InlineAdaptiveAdSize);
  LARGE_BANNER: FixedAdSize;
  LEADERBOARD: FixedAdSize;
  MEDIUM_RECTANGLE: FixedAdSize;
}
Predefined ad sizes and helper methods for creating adaptive and custom sizes.

Functions


canRequestAds

canRequestAds(): boolean
Checks whether the current consent status permits you to request ads.
Returns
boolean true if you can request ads, false otherwise.

getConsentStatus

getConsentStatus(): ConsentStatus
Gets the user's current consent status.
Returns
ConsentStatus The current consent status.

getInitializationStatus

getInitializationStatus(): InitializationStatus
Gets the SDK initialization status.

Use this method to check if the SDK has finished initializing and to inspect the status of individual mediation adapters.
Returns
InitializationStatus The current initialization status.

getPrivacyOptionsRequirementStatus

getPrivacyOptionsRequirementStatus(): PrivacyOptionsRequirementStatus
Checks whether a privacy options entry point is required for your app.

If an entry point is required, add a visible and interactable UI element to your app that calls showPrivacyOptionsForm to display the privacy options form. If an entry point isn't required, configure your UI element to not be visible and interactable.
Returns
PrivacyOptionsRequirementStatus The privacy options requirement status.

getRequestConfiguration

getRequestConfiguration(): RequestConfiguration
Gets the global request configuration.

Use this method to retrieve the current request configuration that has been applied globally.
Returns
RequestConfiguration The current global request configuration.

initialize

initialize(config, onInitializationComplete?): void
Initializes the Google Mobile Ads SDK.

Call this method before loading an ad and before interacting with the rest of the Google Mobile Ads SDK.
Parameters
config: InitializationConfig Options to control SDK initialization.
Optional onInitializationComplete: ((status) => void) A callback function to be run when the SDK finishes initializing.

isConsentFormAvailable

isConsentFormAvailable(): boolean
Checks whether a consent form is available.
Returns
boolean true if a consent form is available, false otherwise.

loadAndShowConsentFormIfRequired

loadAndShowConsentFormIfRequired(onDismissed?): void
Loads a consent form and presents it to the user if their current consent status requires it (e.g., status is REQUIRED).
Parameters
Optional onDismissed: ((error?) => void) Callback function invoked when the form is dismissed or if no form is required, with an optional FormError if the presentation failed.

openAdInspector

openAdInspector(_listener): void
Opens the Google Mobile Ads SDK Ad Inspector overlay.

Use this method to debug mediation setups and ad sources.
Parameters
_listener: OnAdInspectorClosedListener

openDebugMenu

openDebugMenu(adUnitId): void
Opens the debug menu.

Use this method to open the debug menu for a specific ad unit to assist in testing and troubleshooting ad configurations.
Parameters
adUnitId: string The ad unit ID to open the debug menu for.

parseLoadAdError

parseLoadAdError(error): LoadAdError
Parses a native error thrown during ad load and wraps it in a LoadAdError.
Parameters
error: unknown The error object thrown by the native module.
Returns
LoadAdError A parsed LoadAdError object.

requestConsentInfoUpdate

requestConsentInfoUpdate(params?, onComplete?): void
Requests a consent information update.

This API must be called in each app session before calling getConsentStatus.

After this API is called, the getConsentStatus return value is updated synchronously to hold the consent state from the previous app session, if one exists.

getConsentStatus can be updated again to the up-to-date status after the onComplete callback is invoked.
Parameters
Optional params: ConsentRequestParameters Optional configurations for debugging and targeting.
Optional onComplete: ((error?) => void) Callback function invoked when the consent information update finishes, with an optional FormError if the request failed.

reset

reset(): void
Clears all consent state from persistent storage.

Use for debugging purposes only.

setPublisherFirstPartyIdEnabled

setPublisherFirstPartyIdEnabled(enabled): void
Controls whether the publisher first-party ID is enabled.

Enables or disables the Google Mobile Ads SDK publisher first-party ID, formerly known as the same app key.
See also
Parameters
enabled: boolean True to enable the publisher first-party ID; false to disable. Defaults to true.

setRequestConfiguration

setRequestConfiguration(_config): void
Sets the global request configuration for compliance and targeting.

Use this method to specify targeting details, such as maximum ad content rating, compliance settings, such as tag for age treatment, and test device IDs.
Parameters
_config: RequestConfiguration

setUserControlledAppVolume

setUserControlledAppVolume(volume): void
Sets the user-controlled application's audio volume.

Use this method to adjust the audio volume of all ads relative to other audio output on the device.
Parameters
volume: number The volume level, between 0.0 (silent) and 1.0 (maximum). Any floating-point value within this range is valid (for example, 0.001 or 0.33333). The value isn't restricted to specific step-size increments, such as 0.1.

setUserMutedApp

setUserMutedApp(muted): void
Sets whether the application is muted.

Use this method to control the initial audio mute state of subsequent ads.
Parameters
muted: boolean Whether the application audio should be muted. Defaults to false.

showPrivacyOptionsForm

showPrivacyOptionsForm(onDismissed?): void
Shows the privacy options form.

Presents a privacy options form if getPrivacyOptionsRequirementStatus is REQUIRED.

This method should only be called in response to user input to request a privacy options form to be shown.

The privacy options form is preloaded by the SDK automatically when a form becomes available. If no form has been preloaded, the SDK will try to load one asynchronously.

The onDismissed callback is called after the user is presented with the form, selects an option, and dismisses the form. It can also return with a FormError if:
  • The form isn't available.
  • The form fails to show.
  • The form is still being preloaded.
Parameters
Optional onDismissed: ((error?) => void) Callback function invoked when the form is dismissed, with an optional FormError if the presentation failed.