This guide is intended for publishers who want to monetize a Unity app.
Integrating the Google Mobile Ads Unity plugin into an app is the first step toward displaying AdMob ads and earning revenue. Once the integration is complete, you can choose an ad format, such as native or rewarded, to get detailed implementation steps.
Prerequisites
- Use Unity 2019.4 or higher
- To deploy to iOS
- Xcode 14.1 or higher
- Target iOS 11.0 or higher
- CocoaPods
- To deploy to Android
- Minimum Android API level of 21 or higher
- Target Android API level 31 or higher
- Recommended: Create an AdMob account and register an Android or iOS app
Download the Mobile Ads Unity plugin
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.
Use the following links to download the Unity package for the plugin or to take a look at its code on GitHub.
DOWNLOAD THE PLUGIN VIEW SOURCE
Import the Mobile Ads Unity plugin
Google Mobile Ads for Unity is distributed by a Unity asset
package.
To import the package, open your project in the Unity editor, select
Assets > Import Package > Custom Package, and find the
GoogleMobileAdsPlugin.unitypackage
file you downloaded. Make sure all of the
files are selected and click Import.
Include external dependencies
The Google Mobile Ads Unity plugin is distributed with the Unity Play Services Resolver library. This library is intended for use by any Unity plugin that requires access to Android-specific libraries, such as AARs, or iOS CocoaPods. It provides Unity plugins the ability to declare dependencies, which are then automatically resolved and copied into your Unity project.
Follow these steps to ensure that your project includes all the dependencies:
Android
Go to Project Settings > Player > Android > Publishing Settings > Build and select:
- Custom Main Gradle Template
- Custom Gradle Properties Template
In the Unity editor, select Assets > External Dependency Manager > Android
Resolver > Resolve to have the Unity External Dependency Manager library
copy the declared dependencies into the Assets/Plugins/Android
directory
of your Unity app.
iOS
No additional steps are required to include the Google Mobile Ads SDK into the Unity project.
- When using Unity 5.6 or higher, an xcworkspace is generated that includes the required dependency libraries. Use the generated xcworkspace instead of the standard Xcode project.
- When using earlier versions of Unity, the dependencies are included inside the standard Xcode project.
Set your AdMob app ID
In the Unity editor, select Assets > Google Mobile Ads > Settings from the menu.
Enter your Android and iOS AdMob app ID in each field.
Initialize the SDK
Before loading ads, have your app initialize the Google Mobile Ads SDK by
calling MobileAds.Initialize()
. This needs to be done only once, ideally at
app launch.
Here's an example of how to call Initialize()
within the Start()
method
of a script attached to a GameObject
:
...
using GoogleMobileAds.Api;
...
public class GoogleMobileAdsDemoScript : MonoBehaviour
{
public void Start()
{
// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize(initStatus => { });
}
}
If you're using mediation, wait until the callback occurs before loading ads to ensure that all mediation adapters are initialized.
Select an ad format
The Google Mobile Ads SDK 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
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.
Interstitial
Interstitial ad units show full-page ads in your app. Place them at natural breaks & transitions in your app's interface, such as after level completion in a gaming app.
Native
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.
Rewarded
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.
Rewarded interstitial
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
App Open
App open is an ad format that appears when users open or switch back to your app. The ad overlays the loading screen.