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 an Android app.
Supported integrations and ad formats
The mediation adapter for Unity Ads has the following capabilities:
Integration | |
---|---|
Bidding | |
Waterfall | |
Formats | |
Banner | |
Interstitial | |
Rewarded | |
Native |
Requirements
- Android API level 21 or higher
Latest Google Mobile Ads SDK
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。
创建广告单元
前往创收 >广告单元,然后点击添加广告单元。
输入广告单元名称,然后选择平台和广告格式。
最后,点击创建以保存您的广告单元。
添加展示位置
创建项目后,依次点击创收 >展示位置。接收者 创建新的展示位置时,请点击广告单元的添加展示位置。
填写必要的详细信息,然后点击添加展示位置。
记下展示位置 ID。
找到 Unity Ads Reporting API 密钥
出价
对于出价集成,不需要执行此步骤。
瀑布
除了游戏 ID 和展示位置 ID 之外,您还需要有 Unity Ads API 密钥和组织核心 ID(用于设置 Ad Manager 广告单元 ID。
前往创收 >设置 >API 管理并记录相关信息 Monetization Stats API 访问密钥的权限。
然后,前往创收 >Organization Settings(单位设置)并记下 组织核心 ID 对应的实体。
开启测试模式
您可以从 Unity Ads 信息中心。在项目的 设置,选择测试标签页。
您可以点击应用旁边的“修改”按钮,强制应用测试模式 Google Play 商店 ,选中替换客户端测试模式,然后选择 为所有设备强制开启测试模式(即使用测试广告)。
或者,您也可以通过点击 Add Test Device 按钮。
填写表单并点击保存。
Step 2: Set up Unity Ads demand in Ad Manager UI
กำหนดการตั้งค่าสื่อกลางสำหรับหน่วยโฆษณา
ลงชื่อเข้าใช้บัญชี Ad Manager
ไปที่การแสดงโฆษณา > กลุ่มผลตอบแทน แล้วคลิกปุ่มกลุ่มผลตอบแทนใหม่
ป้อนชื่อที่ไม่ซ้ำสำหรับกลุ่มผลตอบแทน ตั้งค่าสถานะเป็นใช้งานอยู่ เลือกรูปแบบโฆษณา และตั้งค่าประเภทพื้นที่โฆษณาเป็นแอปบนอุปกรณ์เคลื่อนที่ ในส่วนการกำหนดเป้าหมาย > พื้นที่โฆษณา ให้เลือกหน่วยโฆษณาภายใต้พื้นที่โฆษณาและแอปพลิเคชันบนอุปกรณ์เคลื่อนที่ที่คุณต้องการเพิ่มสื่อกลาง
จากนั้น คลิกปุ่มเพิ่มพาร์ทเนอร์ผลตอบแทน
หากมีพาร์ทเนอร์ผลตอบแทนสำหรับUnity Adsอยู่แล้ว คุณก็เลือกได้ มิเช่นนั้น ให้เลือกสร้างพาร์ทเนอร์ผลตอบแทนใหม่
เลือก Unity Ads เป็นเครือข่ายโฆษณา ป้อนชื่อที่ไม่ซ้ำ และเปิดใช้สื่อกลาง
เปิดการรวบรวมข้อมูลอัตโนมัติ แล้วป้อนAPI Key and Organization core ID ที่ได้รับในส่วนก่อนหน้า
เมื่อเลือกพาร์ทเนอร์ผลตอบแทนแล้ว ให้เลือกสื่อกลาง SDK บนอุปกรณ์เคลื่อนที่เป็นประเภทการผสานรวม Android เป็นแพลตฟอร์ม และเลือกใช้งานอยู่เป็นสถานะ ป้อนGame ID and Placement ID ที่ได้รับในส่วนก่อนหน้านี้ จากนั้นป้อนค่า CPM เริ่มต้น
คลิกบันทึกที่ด้านล่างของหน้าเมื่อทำเสร็จแล้ว
Add Unity Ads to GDPR and US state regulations ad partners list
ทำตามขั้นตอนใน การตั้งค่า GDPR และ การตั้งค่ากฎระเบียบของรัฐในสหรัฐอเมริกา เพื่อเพิ่ม Unity Ads ลงในรายชื่อพาร์ทเนอร์โฆษณาตามกฎระเบียบ GDPR และกฎระเบียบของรัฐในสหรัฐอเมริกาใน Ad Manager
Step 3: Import the Unity Ads SDK and adapter
Android Studio integration (recommended)
In your app-level build.gradle.kts
file, add the following implementation
dependencies and configurations. Use the latest versions of the Unity Ads SDK
and adapter:
dependencies {
implementation("com.google.android.gms:play-services-ads:23.3.0")
implementation("com.unity3d.ads:unity-ads:4.12.1")
implementation("com.google.ads.mediation:unity:4.12.2.0")
}
Manual integration
Download the latest Unity Ads SDK (
unity-ads.aar
) from their GitHub repository and add it to your project.Navigate to the Unity Ads adapter artifacts on Google's Maven Repository. Select the latest version, download the Unity Ads adapter's
.aar
file, and add it to your project.
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.
In SDK version 2.0.0, Unity Ads added an API to support privacy settings. The following sample code shows how to pass this consent information to the Unity Ads SDK. Should you choose to pass consent information to the Unity Ads SDK manually, it is recommended that this code is called prior to requesting ads through the Google Mobile Ads SDK.
Java
import com.unity3d.ads.metadata.MetaData;
// ...
MetaData gdprMetaData = new MetaData(this);
gdprMetaData.set("gdpr.consent", true);
gdprMetaData.commit();
Kotlin
import com.unity3d.ads.metadata.MetaData
// ...
val gdprMetaData = MetaData(this)
gdprMetaData["gdpr.consent"] = true
gdprMetaData.commit()
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.
In SDK version 2.0.0, Unity Ads added an API to support privacy settings. The following sample code shows how to pass this consent information to the Unity Ads SDK. Should you choose to pass consent information to the Unity Ads SDK manually, it is recommended that this code is called prior to requesting ads through the Google Mobile Ads SDK.
Java
import com.unity3d.ads.metadata.MetaData;
// ...
MetaData ccpaMetaData = new MetaData(this);
ccpaMetaData.set("privacy.consent", true);
ccpaMetaData.commit();
Kotlin
import com.unity3d.ads.metadata.MetaData
// ...
val ccpaMetaData = MetaData(this)
ccpaMetaData["privacy.consent"] = true
ccpaMetaData.commit()
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
No additional code is required for Unity Ads integrations.
Step 6: Test your implementation
เปิดใช้โฆษณาทดสอบ
อย่าลืม ลงทะเบียนอุปกรณ์ทดสอบ สำหรับ Ad Manager และเปิดใช้โหมดทดสอบใน Unity Ads UI
ยืนยันโฆษณาทดสอบ
ในการยืนยันว่าคุณได้รับโฆษณาทดสอบจาก 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.getAdapterResponses()
under the following classes:
com.google.ads.mediation.unity.UnityAdapter
com.google.ads.mediation.unity.UnityMediationAdapter
Here are the codes and accompanying messages thrown by the UnityAds adapter when an ad fails to load:
Error code | Reason |
---|---|
0-10 | UnityAds SDK returned an error. See code for more details. |
101 | UnityAds server parameters configured in the Ad Manager 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 specific error. See code for more details. |
Unity Ads Android Mediation Adapter Changelog
Version 4.12.2.0
- Verified compatibility with Unity Ads SDK 4.12.2.
Built and tested with:
- Google Mobile Ads SDK version 23.2.0.
- Unity Ads SDK version 4.12.2.
Version 4.12.1.0
- Verified compatibility with Unity Ads SDK 4.12.1.
Built and tested with:
- Google Mobile Ads SDK version 23.2.0.
- Unity Ads SDK version 4.12.1.
Version 4.12.0.0
- Verified compatibility with Unity Ads SDK 4.12.0.
Built and tested with:
- Google Mobile Ads SDK version 23.1.0.
- Unity Ads SDK version 4.12.0.
Version 4.11.3.0
- Added bidding support for banner, interstitial and rewarded ad formats.
- Verified compatibility with Unity Ads SDK 4.11.3.
Built and tested with:
- Google Mobile Ads SDK version 23.1.0.
- Unity Ads SDK version 4.11.3.
Version 4.11.2.0
- Verified compatibility with Unity Ads SDK 4.11.2.
Built and tested with:
- Google Mobile Ads SDK version 23.0.0.
- Unity Ads SDK version 4.11.2.
Version 4.10.0.0
- Updated the minimum required Google Mobile Ads SDK version to 23.0.0.
- Verified compatibility with Unity Ads SDK 4.10.0.
Built and tested with:
- Google Mobile Ads SDK version 23.0.0.
- Unity Ads SDK version 4.10.0.
Version 4.9.3.0
- Verified compatibility with Unity Ads SDK 4.9.3.
Built and tested with:
- Google Mobile Ads SDK version 22.6.0.
- Unity Ads SDK version 4.9.3.
Version 4.9.2.0
- Verified compatibility with Unity Ads SDK 4.9.2.
Built and tested with:
- Google Mobile Ads SDK version 22.3.0.
- Unity Ads SDK version 4.9.2.
Version 4.9.1.0
- Updated the minimum required Google Mobile Ads SDK version to 22.3.0.
- Verified compatibility with Unity Ads SDK 4.9.1.
Built and tested with:
- Google Mobile Ads SDK version 22.3.0.
- Unity Ads SDK version 4.9.1.
Version 4.8.0.0
- Reports ad impression when Unity Ads SDK invokes its new onBannerShown() callback method.
- Verified compatibility with Unity Ads SDK 4.8.0.
Built and tested with:
- Google Mobile Ads SDK version 22.2.0.
- Unity Ads SDK version 4.8.0.
Version 4.7.1.0
- Verified compatibility with Unity Ads SDK 4.7.1.
Built and tested with:
- Google Mobile Ads SDK version 22.1.0.
- Unity Ads SDK version 4.7.1.
Version 4.7.0.0
- Verified compatibility with Unity Ads SDK 4.7.0.
Built and tested with:
- Google Mobile Ads SDK version 22.0.0.
- Unity Ads SDK version 4.7.0.
Version 4.6.1.1
- Updated adapter to use new
VersionInfo
class. - Updated the minimum required Google Mobile Ads SDK version to 22.0.0.
Built and tested with:
- Google Mobile Ads SDK version 22.0.0.
- Unity Ads SDK version 4.6.1.
Version 4.6.1.0
- Verified compatibility with Unity Ads SDK 4.6.1.
Built and tested with:
- Google Mobile Ads SDK version 21.5.0
- Unity Ads SDK version 4.6.1.
Version 4.6.0.0
- Added support for forwarding COPPA information to the Unity Ads SDK.
- Verified compatibility with Unity Ads SDK 4.6.0.
- Updated the minimum required Google Mobile Ads SDK version to 21.5.0.
Built and tested with:
- Google Mobile Ads SDK version 21.5.0
- Unity Ads SDK version 4.6.0.
Version 4.5.0.0
- Verified compatibility with Unity Ads SDK 4.5.0.
- Updated the minimum required Google Mobile Ads SDK version to 21.4.0.
Built and tested with:
- Google Mobile Ads SDK version 21.4.0
- Unity Ads SDK version 4.5.0.
Version 4.4.1.0
- Verified compatibility with Unity Ads SDK 4.4.1.
Built and tested with:
- Google Mobile Ads SDK version 21.2.0
- Unity Ads SDK version 4.4.1.
Version 4.4.0.0
- Verified compatibility with Unity Ads SDK 4.4.0.
- Updated the minimum required Google Mobile Ads SDK version to 21.2.0.
Built and tested with:
- Google Mobile Ads SDK version 21.2.0
- Unity Ads SDK version 4.4.0.
Version 4.3.0.0
- Verified compatibility with Unity Ads SDK 4.3.0.
- The
onAdOpened()
callback is now forwarded when interstitial and rewarded ads start playing.
Built and tested with:
- Google Mobile Ads SDK version 21.1.0
- Unity Ads SDK version 4.3.0.
Version 4.2.1.1
- Updated
compileSdkVersion
andtargetSdkVersion
to API 31. - Updated the minimum required Google Mobile Ads SDK version to 21.0.0.
Built and tested with:
- Google Mobile Ads SDK version 21.0.0.
- Unity Ads SDK version 4.2.1.
Version 4.2.1.0
- Verified compatibility with Unity Ads SDK 4.2.1.
Built and tested with:
- Google Mobile Ads SDK version 20.6.0.
- Unity Ads SDK version 4.2.1.
Version 4.1.0.0
- Verified compatibility with Unity Ads SDK 4.1.0.
Built and tested with:
- Google Mobile Ads SDK version 20.6.0.
- Unity Ads SDK version 4.1.0.
Version 4.0.1.0
- Verified compatibility with Unity Ads SDK 4.0.1.
- Updated the minimum required Google Mobile Ads SDK version to 20.6.0.
Built and tested with:
- Google Mobile Ads SDK version 20.6.0.
- Unity Ads SDK version 4.0.1.
Version 4.0.0.0
- Verified compatibility with Unity Ads SDK 4.0.0.
- Updated the minimum required Google Mobile Ads SDK version to 20.5.0.
Built and tested with:
- Google Mobile Ads SDK version 20.5.0.
- Unity Ads SDK version 4.0.0.
Version 3.7.5.0
- Verified compatibility with Unity Ads SDK 3.7.5.
Built and tested with:
- Google Mobile Ads SDK version 20.2.0.
- Unity Ads SDK version 3.7.5.
Version 3.7.4.0
- Verified compatibility with Unity Ads SDK 3.7.4.
Built and tested with:
- Google Mobile Ads SDK version 20.2.0.
- Unity Ads SDK version 3.7.4.
Version 3.7.2.0
- Verified compatibility with Unity Ads SDK 3.7.2.
- Updated the minimum required Google Mobile Ads SDK version to 20.2.0.
Built and tested with:
- Google Mobile Ads SDK version 20.2.0.
- Unity Ads SDK version 3.7.2.
Version 3.7.1.0
- Verified compatibility with Unity Ads SDK 3.7.1.
- Updated the minimum required Google Mobile Ads SDK version to 20.1.0.
Built and tested with:
- Google Mobile Ads SDK version 20.1.0.
- Unity Ads SDK version 3.7.1.
Version 3.6.2.0
- Verified compatibility with Unity Ads SDK 3.6.2.
- Fixed an issue where rewarded ads were not forwarding click callbacks.
- The UnityAds SDK has been removed from the bundled adapter build. Publishers are now required to manually include the UnityAds SDK as an additional dependency.
- Updated the minimum required Google Mobile Ads SDK version to 19.8.0.
Built and tested with:
- Google Mobile Ads SDK version 19.8.0.
- Unity Ads SDK version 3.6.2.
Version 3.6.0.0
- Verified compatibility with Unity Ads SDK 3.6.0.
- Updated the minimum required Google Mobile Ads SDK version to 19.6.0.
Built and tested with:
- Google Mobile Ads SDK version 19.6.0.
- Unity Ads SDK version 3.6.0.
Version 3.5.1.1
- Fixed an issue where when trying to request for multiple interstitial and rewarded ads.
Built and tested with:
- Google Mobile Ads SDK version 19.5.0.
- Unity Ads SDK version 3.5.1.
Version 3.5.1.0
- Verified compatibility with Unity Ads SDK 3.5.1.
- Fixed an issue that causes smart banner ad requests to fail.
Built and tested with:
- Google Mobile Ads SDK version 19.5.0.
- Unity Ads SDK version 3.5.1.
Version 3.5.0.0
- Verified compatibility with Unity Ads SDK 3.5.0.
- Added adaptive banner support.
- Updated the minimum required Google Mobile Ads SDK version to 19.5.0.
Built and tested with:
- Google Mobile Ads SDK version 19.5.0.
- Unity Ads SDK version 3.5.0.
Version 3.4.8.0
- Fixed a
NullPointerException
error that occurs when a banner ad is destroyed. - Updated the minimum required Google Mobile Ads SDK version to 19.3.0.
Built and tested with:
- Google Mobile Ads SDK version 19.3.0.
- Unity Ads SDK version 3.4.8.
Version 3.4.6.1
- Created an adapter build that does not include the Unity Ads SDK bundled in.
This gives publishers an option to use the Unity Ads Services when mediating on
Unity to avoid conflicting dependency issues.
- Publishers may opt to use this by including the
com.google.ads.mediation:unity-adapter-only:x.y.z.p
dependency on their app-levelbuild.gradle
file.
- Publishers may opt to use this by including the
Built and tested with:
- Google Mobile Ads SDK version 19.1.0.
- Unity Ads SDK version 3.4.6.
Version 3.4.6.0
- Verified compatibility with Unity Ads SDK 3.4.6.
- Adapter now forwards the
onAdOpened()
callback when a banner ad is clicked.
Built and tested with:
- Google Mobile Ads SDK version 19.1.0.
- Unity Ads SDK version 3.4.6.
Version 3.4.2.3
- Added descriptive error codes and reasons for adapter load/show failures.
- Updated the minimum required Google Mobile Ads SDK version to 19.1.0.
Built and tested with:
- Google Mobile Ads SDK version 19.1.0.
- Unity Ads SDK version 3.4.2.
Version 3.4.2.2
- Fixed a
ConcurrentModificationException
crash that occurred when Unity Ads returns an error.
Built and tested with:
- Google Mobile Ads SDK version 19.0.1.
- Unity Ads SDK version 3.4.2.
Version 3.4.2.1
- Improved forwarding of Unity's errors to recognize initialization and ad load failures earlier and reduce timeouts.
- Updated the minimum required Google Mobile Ads SDK version to 19.0.1.
Built and tested with:
- Google Mobile Ads SDK version 19.0.1.
- Unity Ads SDK version 3.4.2.
Version 3.4.2.0
- Verified compatibility with Unity Ads SDK 3.4.2.
- Updated the minimum required Google Mobile Ads SDK version to 18.3.0.
Built and tested with:
- Google Mobile Ads SDK version 18.3.0.
- Unity Ads SDK version 3.4.2.
Version 3.4.0.0
- Verified compatibility with Unity Ads SDK 3.4.0.
- Updated the minimum required Google Mobile Ads SDK version to 18.3.0.
Built and tested with:
- Google Mobile Ads SDK version 18.3.0.
- Unity Ads SDK version 3.4.0.
Version 3.3.0.0
- Verified compatibility with Unity Ads SDK 3.3.0.
Built and tested with:
- Google Mobile Ads SDK version 18.2.0.
- Unity Ads SDK version 3.3.0.
Version 3.2.0.1
- Fixed a null pointer exception crash that occurred when calling
loadAd()
before callingUnityAds.initialize()
. - Updated the minimum required Google Mobile Ads SDK version to 18.2.0.
Version 3.2.0.0
- Fixed an issue that caused Banner Ad requests to fail.
- Verified compatibility with Unity Ads SDK 3.2.0.
- Migrated the adapter to AndroidX.
- Updated the minimum required Google Mobile Ads SDK version to 18.1.1.
Version 3.1.0.0
- Added support for flexible banner ad sizes.
- Adapter fails the ad request if the requested size isn't compatible with any Unity Ads banner sizes
- Verified compatibility with Unity Ads SDK 3.1.0.
Version 3.0.1.0
- Verified compatibility with Unity Ads SDK 3.0.1.
- Fixed a bug that caused 'NPE' while showing an interstitial ad.
Version 3.0.0.2
- Updated adapter to support new open-beta Rewarded API.
- Updated the minimum required Google Mobile Ads SDK version to 17.2.0.
Version 3.0.0.1
- Added support for Unity Ads Banner.
Version 3.0.0.0
- Verified compatibility with Unity Ads SDK 3.0.0.
Version 2.3.0.0
- Verified compatibility with Unity Ads SDK 2.3.0.
Version 2.2.1.1
- Updated the adapter to invoke the
onRewardedVideoComplete()
ad event.
Version 2.2.1.0
- Verified compatibility with Unity Ads SDK 2.2.1.
Version 2.2.0.0
- Verified compatibility with Unity Ads SDK 2.2.0.
Version 2.1.2.0
- Verified compatibility with Unity Ads SDK 2.1.2.
Version 2.1.1.0
- Verified compatibility with Unity Ads SDK 2.1.1.
Version 2.1.0.0
- Updated the adapter to make it compatible with Unity Ads SDK 2.1.0.
Version 2.0.8.0
- Verified compatibility with Unity Ads SDK 2.0.8.
Version 2.0.7.0
- Using Unity Ads's click reporting (AdMob and Unity Ads click statistics will match up).
- Added onAdLeftApplication callback support.
Version 2.0.6.0
- Verified compatibility with Unity Ads SDK 2.0.6.
Version 2.0.5.0
- The adapters can now be added as a compile dependency by adding the following
to the build.gradle file's dependencies tag:
compile 'com.google.ads.mediation:unity:2.0.5.0'
- Moved to distributing the adapter as an aar instead of a jar file (see README for additional instructions).
Version 2.0.4.0
- Fixed a bug that caused rewarded video ads to fail to load when an interstitial ad was loaded first.
Version 2.0.2.0
- Changed the version naming system to [Unity Ads SDK version].[adapter patch version].
- Updated the minimum required Unity Ads SDK to v2.0.2.
- Updated the minimum required Google Mobile Ads SDK to v9.0.0.
- Apps are no longer required to call UnityAds.changeActivity(this).
Version 1.0.0
- Initial release. Supports reward-based video ads and interstitial ads.