Back to Blog
Firebase & SDK Integration
2026-08-01 · Updated October 2026
10 min read

Google Mobile Ads (AdMob) Integration in Unity

Initialize the AdMob SDK, load Rewarded Ads, and manage background thread callbacks safely in your Unity project.

AdMobMonetizationUnityMobileSDK
Rohit Rewani
Rohit Rewani — Unity Developer
Unity • C# • Mobile Games • Multiplayer • AR
Google Mobile Ads (AdMob) Integration in Unity cover visual

Integrating Google Mobile Ads

Adding Google Mobile Ads to a Unity project involves configuring your App IDs, initializing the SDK, and managing the lifecycle of ad objects. While this article focuses specifically on Rewarded Ads, the SDK setup and initialization apply to other ad formats too. Because ads load asynchronously, properly handling callbacks and consent flows is an important part of the integration.

Editor Setup & App IDs

To begin, import the official Google Mobile Ads plugin into your Unity project. Before initializing the SDK, you must configure your project to point to your specific AdMob account.

Navigate to Assets > Google Mobile Ads > Settings in the Unity Editor. Here, you must paste your official Android and iOS App IDs. If you fail to do this, your app may crash on launch or fail to serve ads properly, because the manifest will lack the required AdMob metadata.

Consent Gathering (UMP SDK)

Depending on your target regions and applicable privacy regulations (like GDPR in Europe or CPRA in California), you may be legally required to obtain user consent before serving personalized ads. It's important to note that consent is not universally required in every country, but the User Messaging Platform (UMP) SDK handles the regional checks for you.

The typical flow involves checking the consent state via ConsentInformation.Update(), presenting the form if required using ConsentForm.LoadAndShowConsentFormIfRequired(), and finally proceeding to initialize AdMob if ConsentInformation.CanRequestAds() returns true:
csharp
using GoogleMobileAds.Ump.Api;
using GoogleMobileAds.Api;
using UnityEngine;

public class AdMobConsentManager : MonoBehaviour {
    void Start() {
        var requestParameters = new ConsentRequestParameters();

        // 1. Update consent information
        ConsentInformation.Update(requestParameters, (FormError updateError) => {
            if (updateError != null) {
                Debug.LogError("Consent update failed: " + updateError.Message);
                return;
            }
            
            // 2. Load and show the consent form if required by the user's region
            ConsentForm.LoadAndShowConsentFormIfRequired((FormError formError) => {
                if (formError != null) {
                    Debug.LogError("Consent form error: " + formError.Message);
                }
                
                // 3. Initialize AdMob if consent state allows requesting ads
                if (ConsentInformation.CanRequestAds()) {
                    InitializeAdMob();
                }
            });
        });
    }

    private void InitializeAdMob() {
        MobileAds.Initialize((InitializationStatus initStatus) => {
            Debug.Log("AdMob Initialized.");
            // Safe to load ads now
        });
    }
}

Privacy Options (UMP)

In addition to the initial consent form, certain privacy regulations require developers to provide a way for users to revoke or modify their consent at any time. You can check if this is required using ConsentInformation.PrivacyOptionsRequirementStatus. If it returns Required, you should display a button in your app's settings menu that calls ConsentForm.ShowPrivacyOptionsForm() when clicked.

Initialization and Threading

Once MobileAds.Initialize() completes, you can load ads. However, when ads are loaded, shown, or closed, the SDK fires events to notify your code. By default, these ad events may be raised on a background thread. If you try to update a Unity GameObject or UI Text directly from a background thread, Unity may throw cross-thread exceptions or behave unpredictably. To handle this safely, Google provides MobileAdsEventExecutor.ExecuteInUpdate(), which schedules your action to run on Unity's main thread. Alternatively, the plugin allows you to configure the SDK to automatically raise ad events on the Unity main thread via the Editor settings.

Loading a Rewarded Ad

The modern API uses RewardedAd.Load() rather than instantiating a new object directly. It is best practice to clean up old ad references, handle load failures, and immediately preload the next ad once the user closes the current one.
infoAvoid placing time-sensitive telemetry or intense analytics tracking inside ExecuteInUpdate, as the Unity update loop inherently delays the execution of that code.
csharp
using GoogleMobileAds.Api;
using GoogleMobileAds.Common;
using UnityEngine;
using System;

public class RewardedAdController : MonoBehaviour {
    private RewardedAd _rewardedAd;
    private string _adUnitId = "ca-app-pub-3940256099942544/5224354917"; // Standard Android Test ID

    public void LoadAd() {
        // Clean up the old ad before loading a new one
        if (_rewardedAd != null) {
            _rewardedAd.Destroy();
            _rewardedAd = null;
        }

        var adRequest = new AdRequest();
        RewardedAd.Load(_adUnitId, adRequest, (RewardedAd ad, LoadAdError error) => {
            if (error != null || ad == null) {
                Debug.LogError("Ad failed to load: " + error);
                return;
            }
            _rewardedAd = ad;
            RegisterEventHandlers(_rewardedAd);
        });
    }

    public void ShowAd() {
        if (_rewardedAd != null && _rewardedAd.CanShowAd()) {
            _rewardedAd.Show((Reward reward) => {
                // Marshal the reward logic back to the Unity main thread
                MobileAdsEventExecutor.ExecuteInUpdate(() => {
                    Debug.Log("Reward granted! Updating UI...");
                });
            });
        }
    }

    private void RegisterEventHandlers(RewardedAd ad) {
        // Reload a new ad when the user closes the current one
        ad.OnAdFullScreenContentClosed += () => {
            Debug.Log("Ad closed. Preloading the next one.");
            LoadAd();
        };
        
        ad.OnAdFullScreenContentFailed += (AdError error) => {
            Debug.LogError("Ad failed to show: " + error);
            LoadAd();
        };
    }
}

Testing Safely with Test Devices

Testing live ads on your personal device can trigger invalid traffic flags and pose a significant risk to your AdMob account standing. Always use test ad unit IDs during development. If you need to test the production ad unit ID to verify your configuration, you must register your hardware as a test device using RequestConfiguration. Ensure you call this configuration before calling MobileAds.Initialize().

You can find your specific test device ID in the Android Logcat or iOS console output when you make your first ad request. Search the logs for 'Use RequestConfiguration.Builder().setTestDeviceIds' to find your device's ID.
csharp
using System.Collections.Generic;
using GoogleMobileAds.Api;

public class TestDeviceConfigurator {
    public void ConfigureAndInitialize() {
        // WARNING: Remove test device IDs before building your production release!
        List<string> testDeviceIds = new List<string>() { "YOUR_DEVICE_HASH_ID" };
        RequestConfiguration requestConfiguration = new RequestConfiguration {
            TestDeviceIds = testDeviceIds
        };
        MobileAds.SetRequestConfiguration(requestConfiguration);
        
        // Initialize AFTER setting request configuration
        MobileAds.Initialize((InitializationStatus initStatus) => {
            // SDK is ready
        });
    }
}

Frequently Asked Questions

Why am I getting Gradle conflicts after importing AdMob?
AdMob relies heavily on AndroidX and Google Play Services. If you are also using Firebase or other plugins, use EDM4U to resolve the dependencies. See our guide on Common Unity Android Build Errors.

Why are my ads failing to load with "No Fill"?
A "No Fill" error (Error Code 3) simply indicates that the ad request was successful, but the ad network did not have an ad available to send to the app at that time. This can happen for many reasons, including a lack of available inventory for the request, or issues with account configuration.

Will AdMob increase my app download size?
Adding the AdMob SDK will inevitably add some footprint to your build due to included native libraries and resources. You can offset this overhead by stripping your own unused game code and optimizing assets; see our guide on reducing mobile build size.

How do I debug ad load issues on a device?
You can use the Ad Inspector, an in-app overlay that provides real-time information about your ad requests and mediation networks. It requires the Google Mobile Ads Unity plugin version 7.0.0 or higher and only works on registered test devices. You can open it programmatically using MobileAds.OpenAdInspector((AdInspectorError error) => { /* Handle error */ });.

Official References