Share your feedback about the Google Mobile Ads SDK! Take the annual survey.

Get Started

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

Integrating the Google Mobile Ads Unity plugin into an app, which you will do here, 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 video) to get detailed implementation steps.

Prerequisites

Download the Mobile Ads Unity plugin

The Google Mobile Ads Unity plugin enables Unity developers to easily 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 links below 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

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 the Mobile Ads SDK

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 (e.g., 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 the steps listed below to ensure your project includes the Mobile Ads SDK.

Android

In the Unity editor, select Assets > Play Services Resolver > Android Resolver > Resolve. The Unity Play Services Resolver library will copy the declared dependencies into the Assets/Plugins/Android directory of your Unity app.

iOS

No additional steps are required to include the Mobile Ads SDK into the Unity project.

  • When using Unity 5.6 and above, an xcworkspace is generated that includes the required dependency libraries. Use the generated xcworkspace instead of the standard Xcode project.
  • When using older 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.

Enable AdMob by clicking Enabled checkbox under Google AdMob section. Then enter your Android and iOS AdMob app ID in each field.

If your app uses Ad Manager instead of AdMob, enable Google Ad Manager by clicking Enabled checkbox under Google Ad Manager section.

Unity 4 compatibility

If you're using Unity 4, follow the additional steps listed below.

Android

Add the highlighted activity section below to the AndroidManifest.xml file located in the Assets/Plugins/Android/GoogleMobileAdsPlugin directory of your Unity project.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.google.unity"
   android:versionName="1.0"
   android:versionCode="1">
 <uses-sdk android:minSdkVersion="14"
     android:targetSdkVersion="19" />
 <application>
 <activity android:name="com.unity3d.player.UnityPlayerNativeActivity"
   android:label="@string/app_name">
   <intent-filter>
     <action android:name="android.intent.action.MAIN" />
     <category android:name="android.intent.category.LAUNCHER" />
   </intent-filter>
   <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
   <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik"
       android:value="true" />
</activity>
 </application>
</manifest>

iOS

Modify the following build settings within the Xcode project generated by Unity:

  1. Set Enable Modules (C and Objective-C) to Yes in Build Settings.
  2. Add $(inherited) to Other Linker Flags in Build Settings.

Initialize MobileAds

Before loading ads, have your app initialize the 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 are using mediation, you may wish to wait until the callback occurs before loading ads, as this will ensure that all mediation adapters are initialized.

Select an ad format

The 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 best fits your user experience needs.

Banner ads are rectangular image or text ads that occupy a spot within an app's layout. They stay on screen while users are interacting with the app, and can refresh automatically after a certain period of time. If you're new to mobile advertising, they're a great place to start.

Implement a Banner

Interstitial

Interstitials are full-screen ads that cover the interface of an app until closed by the user. They're best used at natural pauses in the flow of an app's execution, such as in between levels of a game or just after completing a task.

Implement an Interstitial

Native

Native is a component-based ad format that gives you the freedom to customize the way assets such as headlines and calls to action are presented in their apps. By choosing fonts, colors, and other details for yourself, you can create natural, unobtrusive ad presentations that can add to a rich user experience.

Implement Native Ads

Rewarded

Rewarded video ads are full-screen video ads that users have the option of watching in full in exchange for in-app rewards.

Implement Rewarded Ads Implement Rewarded Ads (new APIs)

Оставить отзыв о...

Текущей странице
Нужна помощь? Обратитесь в службу поддержки.