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
-
SDK Lifecycle & Initialization: Use
initializewithInitializationConfigto initialize the SDK, and inspect adapter initialization statuses withgetInitializationStatusandInitializationStatus. -
User Messaging Platform (UMP): Manage user consent
with
requestConsentInfoUpdate,loadAndShowConsentFormIfRequired,showPrivacyOptionsForm, and inspect consent state withgetConsentStatusandcanRequestAds. -
Request Configuration: Define global targeting and
policy settings with
setRequestConfigurationandRequestConfiguration, configuring options such asAgeRestrictedTreatment,MaxAdContentRating, andPublisherPrivacyPersonalizationState. -
Ad Formats: Load and present ads using format classes
such as
AppOpenAd,InterstitialAd,RewardedAd, andRewardedInterstitialAd. -
Developer Tools: Inspect ad delivery, adapter status,
and SDK configurations in real-time using
openAdInspectororopenDebugMenu.
| Type Aliases | |
|---|---|
Adapter
|
Represents the possible initialization states of a mediation
adapter.
|
Ad
|
Positions for the AdChoices icon in the ad view. |
Ad
|
Format of the ad being requested. |
Ad
|
Error information about why the ad inspector failed.
|
Ad
|
Errors affecting the opening or operation of the ad inspector.
|
Ad
|
Orientation options for inline adaptive and large anchored
adaptive banner ads.
|
Ad
|
Represents the dimensions of an ad. |
Age
|
Defines the age-restricted treatment options for ad requests.
|
Consent
|
Consent status values. |
Debug
|
Debug values for testing geography. |
Form
|
Represents error codes for User Messaging Platform (UMP) form
operation failures.
|
Full
|
|
Load
|
Represents error codes for ad load operation failures.
|
Max
|
Defines the maximum ad content rating for the app, classifying
the types of ads that can be shown.
|
Native
|
Names used to identify standard native ad assets.
|
Native
|
Identifies the format of a loaded native ad. |
Native
|
Preferences for the aspect ratio of returned native ad media.
|
On
|
Interface definition for a callback to be invoked when the ad
inspector UI closes.
|
Precision
|
The precision of the reported ad value. |
Privacy
|
Privacy options requirement status. |
Publisher
|
Indicates the Publisher privacy treatment personalization
states.
|
Resize
|
Options to customize the resize mode of image content in
NativeAdMediaView.
|
Resolved
|
Represents the final resolved state of an ad size after an ad
has loaded.
|
Swipe
|
Directions for custom click swipe gestures. |
| Variables | |
|---|---|
Ad
|
Predefined ad sizes and helper methods for creating adaptive and
custom sizes.
|
| Functions | |
|---|---|
can
|
Checks whether the current consent status permits you to request
ads.
|
get
|
Gets the user's current consent status. |
get
|
Gets the SDK initialization status. |
get
|
Checks whether a privacy options entry point is required for
your app.
|
get
|
Gets the global request configuration. |
initialize
|
Initializes the Google Mobile Ads SDK. |
is
|
Checks whether a consent form is available. |
load
|
Loads a consent form and presents it to the user if their
current consent status requires it (e.g., status is REQUIRED).
|
open
|
Opens the Google Mobile Ads SDK Ad Inspector overlay.
|
open
|
Opens the debug menu. |
parse
|
Parses a native error thrown during ad load and wraps it in a
LoadAdError.
|
request
|
Requests a consent information update. |
reset
|
Clears all consent state from persistent storage.
|
set
|
Controls whether the publisher first-party ID is enabled.
|
set
|
Sets the global request configuration for compliance and
targeting.
|
set
|
Sets the user-controlled application's audio volume.
|
set
|
Sets whether the application is muted. |
show
|
Shows the privacy options form. |
Type Aliases
AdapterState
AdapterState: typeof AdapterState[keyof typeof AdapterState]
| Properties | |
|---|---|
NOT_
|
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]
| Properties | |
|---|---|
BOTTOM_
|
Bottom-left corner of the ad. |
BOTTOM_
|
Bottom-right corner of the ad. |
TOP_
|
Top-left corner of the ad. |
TOP_
|
Top-right corner of the ad. |
AdFormat
AdInspectorError
AdInspectorError:
BaseError<AdInspectorErrorCode>
AdInspectorErrorCode
AdInspectorErrorCode:
typeof AdInspectorErrorCode[keyof typeof AdInspectorErrorCode]
AdOrientation
AdOrientation: typeof AdOrientation[keyof typeof AdOrientation]
| 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.
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]
ConsentStatus
ConsentStatus: typeof ConsentStatus[keyof typeof ConsentStatus]
DebugGeography
DebugGeography: typeof DebugGeography[keyof typeof DebugGeography]
FormErrorCode
FormErrorCode: typeof FormErrorCode[keyof typeof FormErrorCode]
FullScreenContentErrorCode
FullScreenContentErrorCode:
typeof FullScreenContentErrorCode[keyof typeof FullScreenContentErrorCode]
| Properties | |
|---|---|
AD_
|
The ad has already been shown. |
AD_
|
The ad isn't ready to be shown. |
AD_
|
Ad is too large for the scene (iOS only). |
APP_
|
The app isn't in the foreground. |
INTERNAL_
|
Something happened internally; for instance, an exception
occurred when preparing to show ad content.
|
MEDIATION_
|
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]
MaxAdContentRating
MaxAdContentRating:
typeof MaxAdContentRating[keyof typeof MaxAdContentRating]
NativeAdAssetNames
NativeAdAssetNames:
typeof NativeAdAssetNames[keyof typeof NativeAdAssetNames]
NativeAdType
NativeAdType: typeof NativeAdType[keyof typeof NativeAdType]
| Properties | |
|---|---|
BANNER
|
Banner ad. |
CUSTOM_
|
Custom native format ad. |
NATIVE
|
Native ad. |
NativeMediaAspectRatio
NativeMediaAspectRatio:
typeof NativeMediaAspectRatio[keyof typeof NativeMediaAspectRatio]
OnAdInspectorClosedListener
OnAdInspectorClosedListener:
((error?) => void)
PrecisionType
PrecisionType: typeof PrecisionType[keyof typeof PrecisionType]
PrivacyOptionsRequirementStatus
PrivacyOptionsRequirementStatus:
typeof PrivacyOptionsRequirementStatus[keyof typeof PrivacyOptionsRequirementStatus]
| Properties | |
|---|---|
NOT_
|
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]
ResizeMode
ResizeMode: typeof ResizeMode[keyof typeof ResizeMode]
ResolvedAdSize
ResolvedAdSize:
FixedAdSize | FluidAdSize
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]
| 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;
}
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.
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.
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.
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.
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. |
|
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 | |
|---|---|
|
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.
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.
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
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 configurations for debugging and targeting. |
|
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.
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.
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.
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.
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.
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
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
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 | |
|---|---|
|
Callback function invoked when the form is dismissed, with an optional FormError if the presentation failed. |