<br />

The Google Mobile Ads Unity plugin lets Unity developers serve Google mobile ads
on Android and iOS apps without having to write Java or Objective-C code. The
plugin provides a C# interface for requesting ads that is used by C# scripts in
your Unity project.

This guide is intended for publishers who want to monetize a Unity app.

## Prerequisites

- Use Unity Editor 2019.4 or higher.
  - We recommend 2022.2 or higher.
- To deploy to iOS
  - Xcode 16.0 or higher
  - Target iOS 13.0 or higher
  - [CocoaPods](https://guides.cocoapods.org/using/getting-started.html)
- To deploy to Android
  - Minimum Android API level of 24 or higher
  - Target Android API level 35 or higher

<!-- -->

- Recommended: [Create an AdMob
  account](https://support.google.com/admob/answer/2784575) and [register an
  Android or iOS app](https://support.google.com/admob/answer/2773509)

Android API level is set in **Project Settings \> Player \>
Android \> Other Settings \> Other Settings**.

## Import the Mobile Ads for Unity plugin

### OpenUPM-CLI

If you have the [OpenUPM CLI](https://github.com/openupm/openupm-cli#installation)
installed, you can install the OpenUPM registry with the following
command:

    openupm add com.google.ads.mobile


### Remove `.unitypackage` plugin assets

If you are migrating from using a `.unitypackage` to using OpenUPM, you
must manually uninstall the assets from the old location. Remove the
following directories that were imported from the `.unitypackage`:

- Assets/ExternalDependencyManager
- Assets/GoogleMobileAds
- Assets/Plugins/Android/googlemobileads-unity.aar
- Assets/Plugins/Android/GoogleMobileAdsPlugin
- Assets/Plugins/iOS/GADUAdNetworkExtras
- Assets/Plugins/iOS/unity-plugin-library.a <br />

### OpenUPM with UI

1. Open the [package manager settings](https://docs.unity3d.com/Manual/class-PackageManager.html) by selecting the Unity menu option **Edit \> Project Settings \> Package Manager**.
2. Add OpenUPM as a scoped registry to the Package Manager window:

       Name: OpenUPM
       URL: https://package.openupm.com
       Scopes: com.google

3. Open the [package manager menu](https://docs.unity3d.com/Manual/upm-ui-install.html) by selecting the Unity
   menu option **Window \> Package Manager**.

4. Set the manager scope drop-down to select **My Registries**.

   ![](https://developers.google.com/static/admob/images/unity_upm_registry.png)
5. Select the **Google Mobile Ads for Unity** package from the package list
   and press **Install**.


### Remove `.unitypackage` plugin assets

If you are migrating from using a `.unitypackage` to using OpenUPM, you
must manually uninstall the assets from the old location. Remove the
following directories that were imported from the `.unitypackage`:

- Assets/ExternalDependencyManager
- Assets/GoogleMobileAds
- Assets/Plugins/Android/googlemobileads-unity.aar
- Assets/Plugins/Android/GoogleMobileAdsPlugin
- Assets/Plugins/iOS/GADUAdNetworkExtras
- Assets/Plugins/iOS/unity-plugin-library.a <br />

### OpenUPM

1. Fetch the version tag of the most recent release. The tag returned,
   excluding the `v` prefix, is the Google Mobile Ads Unity Plugin version.

   - **macOS and Linux**

         curl -sS https://api.github.com/repos/googleads/googleads-mobile-unity/releases/latest | jq -r '.tag_name'

   - **Windows PowerShell**

         (Invoke-RestMethod -Uri "https://api.github.com/repos/googleads/googleads-mobile-unity/releases/latest").tag_name

2. Modify the `Packages/manifest.json` file to add the OpenUPM scoped
   registry and dependency by using the version obtained from the preceding
   command:

       {
         "scopedRegistries": [
           {
             "name": "google",
             "url": "https://package.openupm.com",
             "scopes": [
               "com.google"
             ]
           }
         ],
         "dependencies": {
           "com.google.ads.mobile": "11.6.0"
         }
       }


### Remove `.unitypackage` plugin assets

If you are migrating from using a `.unitypackage` to using OpenUPM, you
must manually uninstall the assets from the old location. Remove the
following directories that were imported from the `.unitypackage`:

- Assets/ExternalDependencyManager
- Assets/GoogleMobileAds
- Assets/Plugins/Android/googlemobileads-unity.aar
- Assets/Plugins/Android/GoogleMobileAdsPlugin
- Assets/Plugins/iOS/GADUAdNetworkExtras
- Assets/Plugins/iOS/unity-plugin-library.a <br />

### Import from GitHub

1. Download the [`.unitypackage`](https://github.com/googleads/googleads-mobile-unity/releases/latest) release from GitHub.
2. Import the `.unitypackage` file by selecting the Unity menu option **Assets \> Import package \> Custom Package** and importing all items.

### Optional: Disable External Dependency Manager

If you manage Android and iOS libraries with your own build tools, you can
disable the `com.unity.external-dependency-manager` package:

In the Unity Editor, select **Window \> Package Manager** and remove the
**External Dependency Manager** (`com.unity.external-dependency-manager`)
package. Removing this package clears **Enable External Dependency
Manager** in **Assets \> Google Mobile Ads \> Settings**.

> [!NOTE]
> **Note:** Deleting the `GoogleMobileAdsSettings.asset` file resets your settings and reinstalls the `com.unity.external-dependency-manager` package on the next import or Editor load. To reinstall the package later, select **Assets \> Google Mobile Ads \> Settings** and select **Enable External
> Dependency Manager**.

#### Install legacy External Dependency Manager

If your project uses Unity 2022.2 or earlier, you can install Google's
legacy `com.google.external-dependency-manager` package after disabling
Unity's package:

- Download the latest `.unitypackage` file from the [External Dependency Manager for Unity releases page](https://github.com/googlesamples/unity-jar-resolver/releases/latest) and select **Assets \> Import Package \> Custom Package**.
- Run the following OpenUPM CLI command:

      openupm add com.google.external-dependency-manager

#### Configure native dependencies manually

If you don't use an External Dependency Manager package, add the required
libraries from the
`Assets/GoogleMobileAds/Editor/GoogleMobileAdsDependencies.xml` and
`Assets/GoogleMobileAds/Editor/GoogleUmpDependencies.xml` files to your
build files:

- For Android, select **Edit \> Project Settings \> Player \> Android \>
  Publishing Settings \> Build** and enable **Custom Main Gradle
  Template** . Add the required libraries from the
  `GoogleMobileAdsDependencies.xml` and `GoogleUmpDependencies.xml` files
  to the `dependencies` block in the
  `Assets/Plugins/Android/mainTemplate.gradle` file:

      implementation 'com.google.android.gms:play-services-ads:25.5.0'
      implementation 'com.google.android.ump:user-messaging-platform:4.0.0'

  Also add the `androidx.constraintlayout:constraintlayout`,
  `androidx.lifecycle:lifecycle-process`, and `androidx.fragment:fragment`
  packages using the versions in the `GoogleMobileAdsDependencies.xml`
  file.
- For iOS, export your Xcode project. Add the required pods from the
  `GoogleMobileAdsDependencies.xml` and `GoogleUmpDependencies.xml` files
  to the `Podfile` file in your exported project folder:

      pod 'Google-Mobile-Ads-SDK'
      pod 'GoogleUserMessagingPlatform'

  Then run the following command in your exported iOS project folder:

      pod install --repo-update

## Set your AdMob app ID

In the Unity editor, select **Assets \> Google Mobile Ads \> Settings**
from the menu.

![](https://developers.google.com/static/admob/images/unity_gma_inspector_menu.png)

Enter your Android and iOS

[AdMob app ID](https://support.google.com/admob/answer/6232340)

in each field.

![](https://developers.google.com/static/admob/images/unity/settings_app_ids.png)

Google Mobile Ads Unity Plugin saves these settings as text in the
`Assets/GoogleMobileAds/Resources/GoogleMobileAdsSettings.asset`
configuration file.

## Initialize the SDK

Before loading ads, have your app initialize Google Mobile Ads Unity Plugin by
calling `MobileAds.Initialize()`. This needs to be done only once, ideally at
app launch.

> [!WARNING]
> **Warning:** Ads can be preloaded by Google Mobile Ads Unity Plugin or mediation partner SDKs upon calling `MobileAds.Initialize()`. If you need to obtain consent from users in the European Economic Area (EEA), the United Kingdom (UK), or Switzerland, set any request-specific flags, such as `tagForChildDirectedTreatment` or `tag_for_under_age_of_consent`, or otherwise take action before loading ads. Verify you do this before initializing Google Mobile Ads Unity Plugin.

Here's an example of how to call `MobileAds.Initialize()`:

    MobileAds.Initialize((InitializationStatus initstatus) =>
    {
        if (initstatus == null)
        {
            Debug.LogError("Google Mobile Ads initialization failed.");
            return;
        }

        Debug.Log("Google Mobile Ads initialization complete.");

        MobileAdsEventExecutor.ExecuteInUpdate(() =>
        {
            // Interact with UnityEngine objects on the main thread here.
        });
    });

### Interact with Unity objects on the main thread

Google Mobile Ads Unity Plugin raises ad events on a background thread. If
ad callbacks interact with Unity objects, like `UnityEngine`, explicitly
schedule that work on the Unity main thread by using the
`MobileAdsEventExecutor.ExecuteInUpdate` method. For implementation details,
see [Raise ad events on the Unity main thread](https://developers.google.com/admob/unity/global-settings#raise_ad_events_on_the_unity_main_thread).

## Select an ad format

Google Mobile Ads Unity Plugin is now included in your Unity app when deploying to
either the Android or iOS platform. You're now ready to implement an ad. AdMob
offers a number of different ad formats, so you can choose the one that makes
for the best user experience.

### Banner

![](https://developers.google.com/static/admob/images/format-banner.svg)

Banner ad units display rectangular ads that occupy a portion of an app's
layout. They can refresh automatically after a set period of time. This means
users view a new ad at regular intervals, even if they stay on the same
screen in your app. They're also the simplest ad format to implement.

[Implement banner ads](https://developers.google.com/admob/unity/banner)

### Interstitial

![](https://developers.google.com/static/admob/images/format-interstitial.svg)

Interstitial ad units show full-page ads in your app. Place them at natural
breaks and transitions in your app's interface, such as after level completion
in a gaming app.

[Implement interstitial ads](https://developers.google.com/admob/unity/interstitial)

### Native

![](https://developers.google.com/static/admob/images/format-native.svg)

Native ads are ads where you can customize the way assets such as headlines and
calls to action are presented in your apps. By styling the ad yourself, you can
create a natural, unobtrusive ad presentations that can add to a rich user
experience.

[Implement native ads](https://developers.google.com/admob/unity/native)

### Rewarded

![](https://developers.google.com/static/admob/images/format-rewarded.svg)

Rewarded ad units enable users to play games, take surveys, or watch videos to
earn in-app rewards, such as coins, extra lives, or points. You can set
different rewards for different ad units, and specify the reward values and
items the user received.

[Implement rewarded ads](https://developers.google.com/admob/unity/rewarded)

### Rewarded interstitial

![](https://developers.google.com/static/admob/images/format-rewarded-interstitial.svg)

Rewarded interstitial is a new type of incentivized ad format that lets you
offer rewards, such as coins or extra lives, for ads that appear automatically
during natural app transitions.

Unlike rewarded ads, users aren't required to opt in to view a rewarded
interstitial.

Instead of the opt-in prompt in rewarded ads, rewarded interstitials require an
intro screen that announces the reward and gives users a chance to opt out if
they want to do so.

[Implement rewarded interstitial ads](https://developers.google.com/admob/unity/rewarded-interstitial)

### App open

![](https://developers.google.com/static/admob/images/format-app-open.svg)

App open is an ad format that appears when users open or switch back to your
app. The ad overlays the loading screen.

[Implement app open ads](https://developers.google.com/admob/unity/app-open)