firebase::gma

API for Google Mobile Ads with Firebase.

Summary

The GMA API allows you to load and display mobile ads using the Google Mobile Ads SDK. Each ad format has its own header file.

Deprecated. The Google Mobile Ads (GMA) C++ SDK is deprecated as of June 17, 2024 and should not be adopted in projects that don't already use it. It will enter End-of-Maintenance (EoM) on June 17, 2025. Note that versions of the SDK released before the EoM date will continue to function, but no further bug fixes or changes will be released after the EoM date.

Instead of the Google Mobile Ads C++ SDK, consider using the iOS and Android SDKs from AdMob. For support, reach out to the Google Mobile Ads SDK Technical Forum.

Enumerations

AdErrorCode{
  kAdErrorCodeNone,
  kAdErrorCodeUninitialized,
  kAdErrorCodeAlreadyInitialized,
  kAdErrorCodeLoadInProgress,
  kAdErrorCodeInternalError,
  kAdErrorCodeInvalidRequest,
  kAdErrorCodeNetworkError,
  kAdErrorCodeNoFill,
  kAdErrorCodeNoWindowToken,
  kAdErrorCodeAdNetworkClassLoadError,
  kAdErrorCodeServerError,
  kAdErrorCodeOSVersionTooLow,
  kAdErrorCodeTimeout,
  kAdErrorCodeInterstitialAlreadyUsed,
  kAdErrorCodeMediationDataError,
  kAdErrorCodeMediationAdapterError,
  kAdErrorCodeMediationInvalidAdSize,
  kAdErrorCodeInvalidArgument,
  kAdErrorCodeReceivedInvalidResponse,
  kAdErrorCodeRewardedAdAlreadyUsed,
  kAdErrorCodeMediationNoFill,
  kAdErrorCodeAdAlreadyUsed,
  kAdErrorCodeApplicationIdentifierMissing,
  kAdErrorCodeInvalidAdString,
  kAdErrorCodeAppNotInForeground,
  kAdErrorCodeMediationShowError,
  kAdErrorCodeAdNotReady,
  kAdErrorCodeAdTooLarge,
  kAdErrorCodeNotMainThread,
  kAdErrorCodeNotInTestMode,
  kAdErrorCodeInspectorFailedToLoad,
  kAdErrorCodeInsepctorAlreadyOpen,
  kAdErrorCodeImageUrlMalformed,
  kAdErrorCodeUnknown
}
enum
Error codes returned by Future::error().

Typedefs

AdParent typedef
void *
This is a platform specific datatype that is required to create a Google Mobile Ads ad.

Functions

DisableMediationInitialization()
void
Disables mediation adapter initialization on iOS during initialization of the GMA SDK.
DisableSDKCrashReporting()
void
Disables automated SDK crash reporting on iOS.
GetInitializationStatus()
Get the current adapter initialization status.
GetRequestConfiguration()
Gets the global RequestConfiguration.
Initialize(const ::firebase::App & app, InitResult *init_result_out) Deprecated. The Google Mobile Ads C++ SDK is now deprecated. Please see the SDK reference documentation for more information.
Initializes Google Mobile Ads (GMA) via Firebase.
Initialize(JNIEnv *jni_env, jobject activity, InitResult *init_result_out) Deprecated. The Google Mobile Ads C++ SDK is now deprecated. Please see https://developers.google.com/admob/cpp/reference/namespace/firebase/gma for more information.
Initializes Google Mobile Ads (GMA) without Firebase for Android.
Initialize(InitResult *init_result_out) Deprecated. The Google Mobile Ads C++ SDK is now deprecated. Please see https://developers.google.com/admob/cpp/reference/namespace/firebase/gma for more information.
Initializes Google Mobile Ads (GMA) without Firebase for iOS.
InitializeLastResult()
Get the Future returned by a previous call to firebase::gma::Initialize().
OpenAdInspector(AdParent parent, AdInspectorClosedListener *listener)
void
Opens the ad inspector UI.
SetIsSameAppKeyEnabled(bool is_enabled)
void
Controls whether the Google Mobile Ads SDK Same App Key is enabled.
SetRequestConfiguration(const RequestConfiguration & request_configuration)
void
Sets the global RequestConfiguration that will be used for every AdRequest during the app's session.
Terminate()
void
Terminate GMA.

Classes

firebase::gma::AdError

Information about why an ad operation failed.

firebase::gma::AdInspectorClosedListener

Listener to be invoked when the Ad Inspector has been closed.

firebase::gma::AdListener

A listener for receiving notifications during the lifecycle of a BannerAd.

firebase::gma::AdRequest

Contains targeting information used to fetch an ad.

firebase::gma::AdResult

Information about the result of an ad operation.

firebase::gma::AdReward

Describes a reward credited to a user for interacting with a RewardedAd.

firebase::gma::AdSize

The size of a banner ad.

firebase::gma::AdValue

The monetary value earned from an ad.

firebase::gma::AdView

Loads and displays Google Mobile Ads AdView ads.

firebase::gma::AdViewBoundingBoxListener

A listener class that developers can extend and pass to an AdView object's AdView::SetBoundingBoxListener method to be notified of changes to the size of the Ad's bounding box.

firebase::gma::AdapterInitializationStatus

An immutable snapshot of the GMA SDK’s initialization status, categorized by mediation adapter.

firebase::gma::AdapterResponseInfo

Response information for an individual ad network contained within a ResponseInfo object.

firebase::gma::AdapterStatus

A snapshot of a mediation adapter's initialization status.

firebase::gma::FullScreenContentListener

Listener to be invoked when ads show and dismiss full screen content, such as a fullscreen ad experience or an in-app browser.

firebase::gma::InterstitialAd

Loads and displays Google Mobile Ads interstitial ads.

firebase::gma::PaidEventListener

Listener to be invoked when ads have been estimated to earn money.

firebase::gma::ResponseInfo

Information about an ad response.

firebase::gma::RewardedAd

Loads and displays Google Mobile Ads rewarded ads.

firebase::gma::UserEarnedRewardListener

Listener to be invoked when the user earned a reward.

Structs

firebase::gma::BoundingBox

The screen location and dimensions of an AdView once it has been initialized.

firebase::gma::RequestConfiguration

Global configuration that will be used for every AdRequest.

Namespaces

firebase::gma::ump

API for User Messaging Platform.

Enumerations

AdErrorCode

 AdErrorCode

Error codes returned by Future::error().

Properties
kAdErrorCodeAdAlreadyUsed

Will not send request because the ad object has already been used.

kAdErrorCodeAdNetworkClassLoadError

An attempt to load an Ad Network extras class for an ad request has failed.

kAdErrorCodeAdNotReady

The ad is not ready to be shown.

kAdErrorCodeAdTooLarge

Ad is too large for the scene.

kAdErrorCodeAlreadyInitialized

The ad is already initialized (repeat call).

kAdErrorCodeAppNotInForeground

The ad can not be shown when app is not in the foreground.

kAdErrorCodeApplicationIdentifierMissing

Will not send request because the application identifier is missing.

kAdErrorCodeImageUrlMalformed

Error processing image url.

kAdErrorCodeInsepctorAlreadyOpen

The request to show the Ad Inspector failed because it's already open.

kAdErrorCodeInspectorFailedToLoad

An attempt to load the Ad Inspector failed.

kAdErrorCodeInternalError

A call to load an ad has failed due to an internal SDK error.

kAdErrorCodeInterstitialAlreadyUsed

Will not send request because the interstitial object has already been used.

kAdErrorCodeInvalidAdString

Android Ad String is invalid.

kAdErrorCodeInvalidArgument

Invalid argument error.

kAdErrorCodeInvalidRequest

A call to load an ad has failed due to an invalid request.

kAdErrorCodeLoadInProgress

A call has failed because an ad is currently loading.

kAdErrorCodeMediationAdapterError

Error finding or creating a mediation ad network adapter.

kAdErrorCodeMediationDataError

The mediation response was invalid.

kAdErrorCodeMediationInvalidAdSize

Attempting to pass an invalid ad size to an adapter.

kAdErrorCodeMediationNoFill

A mediation ad network adapter received an ad request, but did not fill.

The adapter’s error is included as an underlyingError.

kAdErrorCodeMediationShowError

A mediation adapter failed to show the ad.

kAdErrorCodeNetworkError

A call to load an ad has failed due to a network error.

kAdErrorCodeNoFill

A call to load an ad has failed because no ad was available to serve.

kAdErrorCodeNoWindowToken

An attempt has been made to show an ad on an Android Activity that has no window token (such as one that's not done initializing).

kAdErrorCodeNone

Call completed successfully.

kAdErrorCodeNotInTestMode

A debug operation failed because the device is not in test mode.

kAdErrorCodeNotMainThread

Attempted to present ad from a non-main thread.

This is an internal error which should be reported to support if encountered.

kAdErrorCodeOSVersionTooLow

The current device’s OS is below the minimum required version.

kAdErrorCodeReceivedInvalidResponse

Received invalid response.

kAdErrorCodeRewardedAdAlreadyUsed

Will not send a request because the rewarded ad object has already been used.

kAdErrorCodeServerError

The ad server experienced a failure processing the request.

kAdErrorCodeTimeout

The request was unable to be loaded before being timed out.

kAdErrorCodeUninitialized

The ad has not been fully initialized.

kAdErrorCodeUnknown

Fallback error for any unidentified cases.

Typedefs

AdParent

void * AdParent

This is a platform specific datatype that is required to create a Google Mobile Ads ad.

The following defines the datatype on each platform:

  • Android: A jobject which references an Android Activity.
  • iOS: An id which references an iOS UIView.
A void pointer for stub classes.

Functions

DisableMediationInitialization

void DisableMediationInitialization()

Disables mediation adapter initialization on iOS during initialization of the GMA SDK.

Calling this method may negatively impact your ad performance and should only be called if you will not use GMA SDK controlled mediation during this app session. This method must be called before initializing the GMA SDK or loading ads and has no effect once the SDK has been initialized.

This method has no effect on Android.

DisableSDKCrashReporting

void DisableSDKCrashReporting()

Disables automated SDK crash reporting on iOS.

If not called, the SDK records the original exception handler if available and registers a new exception handler. The new exception handler only reports SDK related exceptions and calls the recorded original exception handler.

This method has no effect on Android.

GetInitializationStatus

AdapterInitializationStatus GetInitializationStatus()

Get the current adapter initialization status.

You can poll this method to check which adapters have been initialized.

GetRequestConfiguration

RequestConfiguration GetRequestConfiguration()

Gets the global RequestConfiguration.

Details
Returns
the currently active RequestConfiguration that's being used for every ad request.

Initialize

Future< AdapterInitializationStatus > Initialize(
  const ::firebase::App & app,
  InitResult *init_result_out
)

Initializes Google Mobile Ads (GMA) via Firebase.

Deprecated. The Google Mobile Ads C++ SDK is now deprecated. Please see the SDK reference documentation for more information.

Details
Parameters
app
The Firebase app for which to initialize mobile ads.
init_result_out
Optional: If provided, write the basic init result here. kInitResultSuccess if initialization succeeded, or kInitResultFailedMissingDependency on Android if Google Play services is not available on the current device and the Google Mobile Ads SDK requires Google Play services (for example, when using 'play-services-ads-lite'). Note that this does not include the adapter initialization status, which is returned in the Future.
Returns
If init_result_out is kInitResultSuccess, this Future will contain the initialization status of each adapter once initialization is complete. Otherwise, the returned Future will have kFutureStatusInvalid.

Initialize

Future< AdapterInitializationStatus > Initialize(
  JNIEnv *jni_env,
  jobject activity,
  InitResult *init_result_out
)

Initializes Google Mobile Ads (GMA) without Firebase for Android.

The arguments to Initialize are platform-specific so the caller must do something like this:

#if defined(__ANDROID__)
firebase::gma::Initialize(jni_env, activity);
#else
firebase::gma::Initialize();
#endif

Deprecated. The Google Mobile Ads C++ SDK is now deprecated. Please see https://developers.google.com/admob/cpp/reference/namespace/firebase/gma for more information.

Details
Parameters
jni_env
JNIEnv pointer.
activity
Activity used to start the application.
init_result_out
Optional: If provided, write the basic init result here. kInitResultSuccess if initialization succeeded, or kInitResultFailedMissingDependency on Android if Google Play services is not available on the current device and the Google Mobile Ads SDK requires Google Play services (for example, when using 'play-services-ads-lite'). Note that this does not include the adapter initialization status, which is returned in the Future.
Returns
If init_result_out is kInitResultSuccess, this Future will contain the initialization status of each adapter once initialization is complete. Otherwise, the returned Future will have kFutureStatusInvalid.

Initialize

Future< AdapterInitializationStatus > Initialize(
  InitResult *init_result_out
)

Initializes Google Mobile Ads (GMA) without Firebase for iOS.

Deprecated. The Google Mobile Ads C++ SDK is now deprecated. Please see https://developers.google.com/admob/cpp/reference/namespace/firebase/gma for more information.

Details
Parameters
init_result_out
Optional: If provided, write the basic init result here. kInitResultSuccess if initialization succeeded, or kInitResultFailedMissingDependency on Android if Google Play services is not available on the current device and the Google Mobile Ads SDK requires Google Play services (for example, when using 'play-services-ads-lite'). Note that this does not include the adapter initialization status, which is returned in the Future.
Returns
If init_result_out is kInitResultSuccess, this Future will contain the initialization status of each adapter once initialization is complete. Otherwise, the returned Future will have kFutureStatusInvalid.

InitializeLastResult

Future< AdapterInitializationStatus > InitializeLastResult()

Get the Future returned by a previous call to firebase::gma::Initialize().

OpenAdInspector

void OpenAdInspector(
  AdParent parent,
  AdInspectorClosedListener *listener
)

Opens the ad inspector UI.

Details
Parameters
parent
The platform-specific UI element that will host the ad inspector. For iOS this should be the window's UIViewController. For Android this is the Activity Context which the GMA SDK is running in.
listener
The listener will be invoked when the user closes the ad inspector UI. firebase::gma::Initialize(). must be called prior to this function.

SetIsSameAppKeyEnabled

void SetIsSameAppKeyEnabled(
  bool is_enabled
)

Controls whether the Google Mobile Ads SDK Same App Key is enabled.

This function must be invoked after GMA has been initialized. The value set persists across app sessions. The key is enabled by default.

This operation is supported on iOS only. This is a no-op on Android systems.

Details
Parameters
is_enabled
whether the Google Mobile Ads SDK Same App Key is enabled.

SetRequestConfiguration

void SetRequestConfiguration(
  const RequestConfiguration & request_configuration
)

Sets the global RequestConfiguration that will be used for every AdRequest during the app's session.

Details
Parameters
request_configuration
The request configuration that should be applied to all ad requests.

Terminate

void Terminate()

Terminate GMA.

Frees resources associated with GMA that were allocated during firebase::gma::Initialize().