This guide shows you how to use the Google Mobile Ads SDK to load and display ads from Unity Ads using mediation, covering waterfall integrations. It covers how to add Unity Ads to an ad unit's mediation configuration, and how to integrate the Unity Ads SDK and adapter into a Unity app.
Supported integrations and ad formats
The AdMob mediation adapter for Unity Ads has the following capabilities:
Integration | |
---|---|
Bidding | 1 |
Waterfall | |
Formats | |
Banner | |
Interstitial | |
Rewarded |
Requirements
- Latest Google Mobile Ads SDK
- Unity 4 or higher
- To deploy on Android
- Android API level 21 or higher
- To deploy on iOS
- iOS deployment target of 12.0 or higher
- A working Unity project configured with Google Mobile Ads SDK. See Get Started for details.
- Complete the mediation Get started guide
Step 1: Set up configurations in Unity Ads UI
注册或登录 Unity Ads。
创建项目
在 Unity Ads 信息中心内,前往 项目,然后点击创建项目。
填写表单,然后点击创建项目以添加您的项目。
前往创收 >开始,然后点击开始。
在 Project Setup 模态窗口中,选择 I plan to use Mediation(我打算使用中介),然后选择 Google AdMob为中介合作伙伴添加广告,然后点击下一步。
选择您的广告设置,然后点击下一步。
填写表单,然后点击添加项目。
记下游戏 ID。
创建广告单元
前往创收 >广告单元,然后点击添加广告单元。
输入广告单元名称,然后选择平台和广告格式。
Android
iOS
最后,点击创建以保存您的广告单元。
添加展示位置
出价
要创建出价展示位置,请与您的 Google 客户经理联系。
瀑布
创建项目后,依次点击创收 >展示位置。接收者 创建新的展示位置时,请点击广告单元的添加展示位置。
填写必要的详细信息,然后点击添加展示位置。
记下展示位置 ID。
Android
iOS
找到 Unity Ads Reporting API 密钥
出价
对于出价集成,不需要执行此步骤。
瀑布
除了游戏 ID 和展示位置 ID 之外,您还需要有 Unity Ads API 密钥和组织核心 ID(用于设置 AdMob 广告单元 ID。
前往创收 >设置 >API 管理并记录相关信息 Monetization Stats API 访问密钥的权限。
然后,前往创收 >Organization Settings(单位设置)并记下 组织核心 ID 对应的实体。
开启测试模式
您可以从 Unity Ads 信息中心。在项目的 设置,选择测试标签页。
您可以点击各应用的测试模式按钮 平台,勾选替换客户端测试模式,然后选择 为所有设备强制开启测试模式(即使用测试广告)。
Android
iOS
或者,您也可以通过点击 Add Test Device 按钮。
填写表单并点击保存。
Step 2: Set up Unity Ads demand in AdMob UI
为广告单元配置中介设置
Add Unity Ads to GDPR and US state regulations ad partners list
按照 GDPR 设置 和 美国州级法规设置 中的步骤,将 Unity Ads 添加到 AdMob 界面中的 GDPR 和美国州级法规广告合作伙伴列表中。
Step 3: Import the Unity Ads SDK and adapter
Download the latest version of Google Mobile Ads mediation plugin for Unity Ads
from the download link in the
Changelog and extract the
GoogleMobileAdsUnityAdsMediation.unitypackage
from the zip
file.
In your Unity project editor, select Assets > Import Package > Custom
Package and choose the GoogleMobileAdsUnityAdsMediation.unitypackage
file
you downloaded. Make sure all the files are selected and click Import.
Then, select Assets > Play Services Resolver > Android Resolver > Force
Resolve. The Unity Play Services Resolver library will perform dependency
resolution from scratch and copy the declared dependencies into the
Assets/Plugins/Android
directory of your Unity app.
Using the Unity Adapter with Unity Ads Services
If you integrate with the Unity Ads SDK through the Services pane, Package Manager, or Asset store, then you already have a copy of the Unity Ads Android SDK in your app. To avoid issues with duplicate symbols when building for Android, you'll need to remove the reference to the Unity Ads SDK.
Update the Assets/GoogleMobileAds/Editor/UnityMediationDependencies.xml
file
and remove the Unity Ads SDK dependency:
<!-- If using the Unity Ads Service from Unity3D, comment out this dependency to
avoid including the Unity Ads Android SDK twice. -->
<androidPackage spec="com.unity3d.ads:unity-ads:x.y.z">
<repositories>
<repository>https://repo.maven.apache.org/maven2/</repository>
</repositories>
</androidPackage>
Step 4: Implement privacy settings on Unity Ads SDK
EU Consent and GDPR
Under the Google EU User Consent Policy, you must ensure that certain disclosures are given to, and consents obtained from, users in the European Economic Area (EEA) regarding the use of device identifiers and personal data. This policy reflects the requirements of the EU ePrivacy Directive and the General Data Protection Regulation (GDPR). When seeking consent, you must identify each ad network in your mediation chain that may collect, receive, or use personal data and provide information about each network's use. Google currently is unable to pass the user's consent choice to such networks automatically.
The Google Mobile Ads mediation plugin for Unity Ads
version 3.3.0
includes the
UnityAds.SetConsentMetaData()
method. The following sample code shows how to pass consent information to the
Unity Ads SDK. If you choose to call this method, it is recommended that you do
so prior to requesting ads through the Google Mobile Ads SDK.
using GoogleMobileAds.Api.Mediation.UnityAds;
// ...
UnityAds.SetConsentMetaData("gdpr.consent", true);
See Unity Ads' Privacy Consent and data APIs and Complying with GDPR guides for more details and the values that can be provided in each method.
US states privacy laws
U.S. states privacy laws require giving users the right to opt out of the "sale" of their "personal information" (as the law defines those terms), with the opt-out offered via a prominent "Do Not Sell My Personal Information" link on the "selling" party's homepage. The U.S. states privacy laws compliance guide offers the ability to enable restricted data processing for Google ad serving, but Google is unable to apply this setting to each ad network in your mediation chain. Therefore, you must identify each ad network in your mediation chain that may participate in the sale of personal information and follow guidance from each of those networks to ensure compliance.
The Google Mobile Ads mediation plugin for Unity Ads
version 3.3.0
includes the
UnityAds.SetConsentMetaData()
method. The following sample code shows how to pass consent information to the
Unity Ads SDK. If you choose to call this method, it is recommended that you do
so prior to requesting ads through the Google Mobile Ads SDK.
using GoogleMobileAds.Api.Mediation.UnityAds;
// ...
UnityAds.SetConsentMetaData("privacy.consent", true);
See Unity Ads' Privacy Consent and data APIs and Complying with CCPA guides for more details and the values that can be provided in each method.
Step 5: Add required code
Android
No Additional code required for Unity Ads Android integrations.
iOS
SKAdNetwork integration
Follow Unity Ads' documentation
to add the SKAdNetwork identifiers to your project's Info.plist
file.
Compile errors
For Unity Ads adapter 3.4.0 or higher, you must follow the integration steps in the Unity documentation.
Step 6: Test your implementation
启用测试广告
请务必为AdMob 注册您的测试设备,并在 Unity Ads 界面中启用测试模式。
验证测试广告
如需验证您收到的是来自Unity Ads的测试广告,请使用相应广告来源在广告检查器中启用单一广告来源测试。 Unity Ads (Waterfall)
Error codes
If the adapter fails to receive an ad from Unity Ads, publishers can check the
underlying error from the ad response using
ResponseInfo
under the
following classes:
Android
com.google.ads.mediation.unity.UnityAdapter
com.google.ads.mediation.unity.UnityMediationAdapter
iOS
GADMAdapterUnity
GADMediationAdapterUnity
Here are the codes and accompanying messages thrown by the UnityAds adapter when an ad fails to load:
Android
Error code | Reason |
---|---|
0-10 | UnityAds SDK returned an error. See code for more details. |
101 | UnityAds server parameters configured in the Admob UI are missing/invalid. |
102 | UnityAds returned a placement with a NO_FILL state. |
103 | UnityAds returned a placement with a DISABLED state. |
104 | UnityAds tried to show an ad with a null context. |
105 | Context used to initialize, load and/or show ads from Unity Ads is not an Activity instance. |
106 | UnityAds tried to show an ad that's not ready to be shown. |
107 | UnityAds is not supported on the device. |
108 | UnityAds can only load 1 ad per placement at a time. |
109 | UnityAds finished with an ERROR state. |
200-204 | UnityAds Banner a specific error. See code for more details. |
iOS
0-9 | UnityAds SDK returned an error. See Unity's documentation for more details. |
101 | UnityAds server parameters configured in the Admob UI are missing/invalid. |
102 | Device not supported by UnityAds. |
103 | UnityAds finished presenting with error state kUnityAdsFinishStateError. |
104 | The Unity ad object is nil after calling its initializer. |
105 | Failed to show Unity Ads due to ad not ready. |
106 | UnityAds called a placement changed callback with placement state kUnityAdsPlacementStateNoFill. |
107 | UnityAds called a placement changed callback with placement state kUnityAdsPlacementStateDisabled. |
108 | An ad was already loaded for this placement. UnityAds SDK does not support loading multiple ads for the same placement. |
Unity Ads Unity Mediation Plugin Changelog
Version Next
- Renamed
DummyClient
toPlaceholderClient
.
Version 3.12.1
- Supports Unity Ads Android adapter version 4.12.1.0.
- Supports Unity Ads iOS adapter version 4.12.1.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 9.1.1.
Version 3.12.0
- Supports Unity Ads Android adapter version 4.12.0.0.
- Supports Unity Ads iOS adapter version 4.12.0.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 9.1.0.
Version 3.11.1
- Supports Unity Ads Android adapter version 4.11.3.0.
- Supports Unity Ads iOS adapter version 4.11.3.1.
- Built and tested with the Google Mobile Ads Unity Plugin version 9.1.0.
Version 3.11.0
- Supports Unity Ads Android adapter version 4.11.3.0.
- Supports Unity Ads iOS adapter version 4.11.3.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 9.1.0.
Version 3.10.0
- Supports Unity Ads Android adapter version 4.10.0.0.
- Supports Unity Ads iOS adapter version 4.10.0.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 9.0.0.
Version 3.9.1
- Supports Unity Ads Android adapter version 4.9.3.0.
- Supports Unity Ads iOS adapter version 4.9.3.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 9.0.0.
Version 3.9.0
- Supports Unity Ads Android adapter version 4.9.2.0.
- Supports Unity Ads iOS adapter version 4.9.2.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 8.6.0.
Version 3.8.0
- Supports Unity Ads Android adapter version 4.8.0.0.
- Supports Unity Ads iOS adapter version 4.8.0.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 8.4.1.
Version 3.7.1
- Supports Unity Ads Android adapter version 4.7.1.0.
- Supports Unity Ads iOS adapter version 4.7.1.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 8.3.0.
Version 3.7.0
- Supports Unity Ads Android adapter version 4.7.0.0.
- Supports Unity Ads iOS adapter version 4.7.0.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 8.1.0.
Version 3.6.1
- Supports Unity Ads Android adapter version 4.6.1.0.
- Supports Unity Ads iOS adapter version 4.6.1.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 8.0.0.
Version 3.6.0
- Moved adapter content to
GoogleMobileAds/Mediation/UnityAds/
. - Refactored adapter namespace to use
GoogleMobileAds.Mediation.UnityAds
. - Supports Unity Ads Android adapter version 4.6.0.0.
- Supports Unity Ads iOS adapter version 4.6.0.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 7.4.1.
Version 3.5.0
- Supports Unity Ads Android adapter version 4.5.0.0.
- Supports Unity Ads iOS adapter version 4.5.0.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 7.3.1.
Version 3.4.1
- Supports Unity Ads Android adapter version 4.4.1.0.
- Supports Unity Ads iOS adapter version 4.4.1.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 7.2.0.
Version 3.4.0
- Supports Unity Ads Android adapter version 4.4.0.0.
- Supports Unity Ads iOS adapter version 4.4.0.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 7.2.0.
Version 3.3.0
- Updated the
SetGDPRConsentMetaData(bool)
method from theUnityAds
class toSetConsentMetaData(string, bool)
. - Supports Unity Ads Android adapter version 4.3.0.0.
- Supports Unity Ads iOS adapter version 4.3.0.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 7.2.0.
Version 3.2.1
- Supports Unity Ads Android adapter version 4.2.1.1.
- Supports Unity Ads iOS adapter version 4.2.1.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 7.0.2.
Version 3.2.0
- Supports Unity Ads Android adapter version 4.2.1.0.
- Supports Unity Ads iOS adapter version 4.2.1.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 7.0.1.
Version 3.1.0
- Supports Unity Ads Android adapter version 4.1.0.0.
- Supports Unity Ads iOS adapter version 4.1.0.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 7.0.0.
Version 3.0.1
- Supports Unity Ads Android adapter version 4.0.1.0.
- Supports Unity Ads iOS adapter version 4.0.1.0.
- Built and tested with the Google Mobile Ads Unity Plugin version 7.0.0.
Version 3.0.0
- Supports Unity Ads Android adapter version 4.0.0.0.
- Supports Unity Ads iOS adapter version 4.0.0.0.
Version 2.7.2
- Supports Unity Ads Android adapter version 3.7.5.0.
- Supports Unity Ads iOS adapter version 3.7.5.0.
Version 2.7.1
- Supports Unity Ads Android adapter version 3.7.2.0.
- Supports Unity Ads iOS adapter version 3.7.2.0.
Version 2.7.0
- Supports Unity Ads Android adapter version 3.7.1.0.
- Supports Unity Ads iOS adapter version 3.7.1.0.
Version 2.6.0
- Supports Unity Ads Android adapter version 3.6.0.0.
- Supports Unity Ads iOS adapter version 3.6.0.0.
Version 2.5.1
- Supports Unity Ads Android adapter version 3.5.1.1.
- Supports Unity Ads iOS adapter version 3.5.1.1.
Version 2.5.0
- Supports Unity Ads Android adapter version 3.5.0.0.
- Supports Unity Ads iOS adapter version 3.5.0.0.
Version 2.4.7
- Supports Unity Ads Android adapter version 3.4.8.0.
- Supports Unity Ads iOS adapter version 3.4.8.0.
Version 2.4.6
- Supports Unity Ads Android adapter version 3.4.6.1.
- Supports Unity Ads iOS adapter version 3.4.6.0.
- Publishers now have an option to use the Unity Ads Services when mediating on Unity.
- See the
Assets/GoogleMobileAds/Editor/UnityMediationDependencies.xml
file for additional details.
- See the
Version 2.4.5
- Supports Unity Ads Android adapter version 3.4.6.0.
- Supports Unity Ads iOS adapter version 3.4.6.0.
Version 2.4.4
- Supports Unity Ads Android adapter version 3.4.2.3.
- Supports Unity Ads iOS adapter version 3.4.2.2.
Version 2.4.3
- Supports Unity Ads Android adapter version 3.4.2.2.
- Supports Unity Ads iOS adapter version 3.4.2.1.
Version 2.4.2
- Supports Unity Ads Android adapter version 3.4.2.1.
- Supports Unity Ads iOS adapter version 3.4.2.1.
Version 2.4.1
- Supports Unity Ads Android adapter version 3.4.2.0.
- Supports Unity Ads iOS adapter version 3.4.2.0.
Version 2.4.0
- Supports Unity Ads Android adapter version 3.4.0.0.
- Supports Unity Ads iOS adapter version 3.4.0.0.
Version 2.3.0
- Supports Unity Ads Android adapter version 3.3.0.0.
- Supports Unity Ads iOS adapter version 3.3.0.0.
Version 2.2.0
- Supports Unity Ads Android adapter version 3.2.0.1.
- Supports Unity Ads iOS adapter version 3.2.0.1.
Version 2.1.0
- Supports Unity Ads Android adapter version 3.1.0.0.
- Supports Unity Ads iOS adapter version 3.1.0.0.
Version 2.0.3
- Updated the plugin to support the new open-beta Rewarded API.
- Adds support for Banner Ads.
- Supports Unity Ads Android adapter version 3.0.0.2.
- Supports Unity Ads iOS adapter version 3.0.0.3.
Version 2.0.2
- Supports Unity Ads Android adapter version 3.0.0.0.
- Supports Unity Ads iOS adapter version 3.0.0.1.
Version 2.0.1
- Fixed an "incompatible type" error that caused issues when building for iOS.
Version 2.0.0
- Supports Unity Ads Android adapter version 3.0.0.0.
- Supports Unity Ads iOS adapter version 3.0.0.0.
Version 1.2.0
- Supports Unity Ads Android adapter version 2.3.0.0.
- Supports Unity Ads iOS adapter version 2.3.0.0.
Version 1.1.3
- Supports Unity Ads Android adapter version 2.2.1.0.
- Supports Unity Ads iOS adapter version 2.2.1.0.
Version 1.1.2
- Supports Unity Ads Android SDK version 2.2.0.
- Supports Unity Ads iOS SDK version 2.2.0.
- Added
UnityAds.SetGdprConsentMetaData()
method to manually request a user opt-in for targeted advertising.
Version 1.1.1
- Supports Unity Ads Android SDK version 2.2.0.
- Supports Unity Ads iOS SDK version 2.2.1.
Version 1.1.0
- Supports Unity Ads Android SDK version 2.2.0.
- Supports Unity Ads iOS SDK version 2.2.0.
Version 1.0.0
- First release!
- Supports Unity Ads Android SDK version 2.1.2.
- Supports Unity Ads iOS SDK version 2.1.2.