- Интеграция Google Mobile Ads Unity plugin в приложение
- Contact
- Заходим в свой аккаунт на
- В Unity проекте
- 1. Импортируем Mobile Ads Unity plugin:
- 2. Убеждаемся что все файлы выбраны и нажимаем Import.
- 3. Включение SDK для мобильных объявлений (подключение зависимостей)
- 4. Устанавливаем AdMob app ID для проекта
- 5. Помещаем рекламу на сцену
- Integration guide for Android (Java)
- Overview
- In this guide:
- Basic ads implementation
- Creating a Project on the Unity Developer Dashboard
- Creating Ad Units in your game
- Importing the Unity Ads framework
- Using Android Studio
- Without Android Studio
- Initializing the Unity Ads SDK
- Interstitial display ads
- Interstitial ads example
- Rewarded video ads
- Rewarded video example
- Rewarded video ad buttons
- Banner ads
- Ad Unit configuration
- app-ads.txt
- Script implementation
- Banner position
- Testing
- Integrating Unity Ads with Mediation
- Supported ad formats and features
- Requirements
- Step 1: Set up Unity ads
- Banner
- Interstitial
- Rewarded
- Step 2: Configure mediation settings for your Ad Manager ad unit
- Using rewarded ads
- Step 3: Import the Unity Ads SDK and adapter
- Android Studio integration (recommended)
- Manual integration
- Step 4: Additional code required
- Step 5: Test your implementation
- Optional steps
- EU consent and GDPR
- Error codes
- Unity Ads Android Mediation Adapter Changelog
- Version 3.7.5.0
- Version 3.7.4.0
- Version 3.7.2.0
- Version 3.7.1.0
- Version 3.6.2.0
- Version 3.6.0.0
- Version 3.5.1.1
- Version 3.5.1.0
- Version 3.5.0.0
- Version 3.4.8.0
- Version 3.4.6.1
- Version 3.4.6.0
- Version 3.4.2.3
- Version 3.4.2.2
- Version 3.4.2.1
- Version 3.4.2.0
- Version 3.4.0.0
- Version 3.3.0.0
- Version 3.2.0.1
- Version 3.2.0.0
- Version 3.1.0.0
- Version 3.0.1.0
- Version 3.0.0.2
- Version 3.0.0.1
- Version 3.0.0.0
- Version 2.3.0.0
- Version 2.2.1.1
- Version 2.2.1.0
- Version 2.2.0.0
- Version 2.1.2.0
- Version 2.1.1.0
- Version 2.1.0.0
- Version 2.0.8.0
- Version 2.0.7.0
- Version 2.0.6.0
- Version 2.0.5.0
- Version 2.0.4.0
- Version 2.0.2.0
- Version 1.0.0
Интеграция Google Mobile Ads Unity plugin в приложение
Contact
Официальная документация по установке
Плагин «Google Mobile Ads» позволяет разработчикам Unity легко показывать Google Mobile Ads в приложениях для Android и iOS без необходимости написания кода Java или Objective-C.
Плагин предоставляет интерфейс C # для запроса рекламы, которая используется скриптами C # в вашем проекте Unity.
- Воспользуйтесь ссылками ниже, чтобы загрузить пакет Unity для плагина или посмотреть его код на GitHub.
Скачать плагин
Исходники
Заходим в свой аккаунт на
6668575966
Они имеют примерно такой вид: ca-app-pub-1429926643964414/8841163868
В Unity проекте
1. Импортируем Mobile Ads Unity plugin:
2. Убеждаемся что все файлы выбраны и нажимаем Import.
3. Включение SDK для мобильных объявлений (подключение зависимостей)
Выполните шаги, перечисленные ниже, чтобы убедиться, что в проекте подключён Mobile Ads SDK.
В основном меню Unity, выберите Assets > Play Services Resolver > Android Resolver > Resolve. Unity Play Services Resolver library скопирует требуемые зависимости в папку Assets/Plugins/Android проекта.
4. Устанавливаем AdMob app ID для проекта
В основном меню Unity выберите Assets > Google Mobile Ads > Settings.
Разрешите AdMob кликнув Enabled на checkbox в Google AdMob секции. Введите Android или iOS AdMob ID приложения в соответствующие поле.
Если же ваше приложение использует Ad Manager вместо AdMob, разрешите Google Ad Manager кликнув на чекбокс в секции Google Ad Manager.
5. Помещаем рекламу на сцену
На сцене, где планируется показ рекламы, в иерархии, заводите пустой объект, например с именем BannerPlace и подключаете к нему скрипт, предварительно прописав свои значения «Идентификатора приложения» и «Идентификаторов рекламных блоков» :
Источник
Integration guide for Android (Java)
Overview
This guide covers basic integration for implementing Unity Ads in your native Android game.
- If you are an iOS developer using Objective-C, click here.
- If you are a Unity developer using C#, click here.
- Click here for the Android (Java) API reference.
In this guide:
Basic ads implementation
Creating a Project on the Unity Developer Dashboard
If you don’t have a Unity Developer (UDN) account yet, create one here. When you have an account, follow these steps to create a Unity Project:
- Log in to the Unity Dashboard.
- From the landing page, navigate to the Monetize service. Click Explore to launch the Monetize Dashboard.
- Select Projects from the navigation bar.
- Click the New Project button.
Locate your Project’s Game ID by selecting your Project, then selecting Project Settings from the navigation bar. From the Project Settings page, go to the Game IDs section. Copy the Google Play Store Game ID, as you will need it to activate the Unity Ads service in your game.
Creating Ad Units in your game
Ad Units are surfacing points that trigger ads in your game. Create Ad Units in the Monetize Dashboard by selecting your project, then selecting Monetization > Ad Units from the navigation bar.
Click the Add Ad Unit button to bring up the creation modal. Enter your Ad Unit ID and select its type:
- Select Rewarded video to allow players to opt-in to viewing ads in exchange for incentives. Rewarded Ad Units do not allow the player to skip the ad.
- Select Interstitial video to show basic interstitial ads or promotional content. Interstitial Ad Units allow players to skip the ad after a specified period of time.
- Select Banner to create a dedicated Banner Ad Unit.
Every Unity Ads-enabled project has one Ad Unit for each format (rewarded, interstitial, and banner) per platform by default. Feel free to use one of these for your first implementation if they suit your needs, or create your own.
For more information, see documentation on Ad Units.
Importing the Unity Ads framework
Download the Unity Ads framework here, specifically unity-ads.aar.
Using Android Studio
- Create or open your existing Android project in Android Studio.
- Add a new module and import the unity-ads.aar file. Name the module «unity-ads», for example.
- Right-click on the module in the project view, then select Open Module Settings >app, and add «unity-ads» module as a dependency.
- Add the following imports to your java Activity file:
Without Android Studio
If you can’t use the .aar packages with your build system, Unity also provides the same resources in a ZIP file (unity-ads.zip in GitHub releases). Follow these steps to use Unity Ads:
- Include classes.jar in your build.
- Manually merge the manifest from AndroidManifest.xml. Make sure you include both AdUnitActivity and AdUnitSoftwareActivity activities. You also need to add the INTERNET and ACCESS_NETWORK_STATE permissions.
- If you are using ProGuard, add all lines from proguard.txt to your ProGuard configuration.
Initializing the Unity Ads SDK
To initialize the SDK, you must reference your Project’s Game ID for the appropriate platform. You can locate the ID on the Monetize Dashboard by selecting the Project, then selecting Project Settings from the navigation bar (see the Dashboard guide section on Project Settings for details).
In your game script, you’ll need to implement an IUnityAdsListener interface that handles ad callbacks. The initialize method to initialize the SDK requires this listener as a parameter. Initialize the SDK early in your game’s run-time life cycle, before you need to show ads. For example:
For the initialize function, the myActivity parameter is the current Android Activity. The unityGameID variable is the Unity Game ID for you Project, found in the developer dashboard. The myAdsListener variable is the listener for IUnityAdsListener callbacks. The true boolean indicates that the game is in test mode, and will only show test ads.
Note: You must implement each of the callback methods in the listener interface, even if they are empty functions for now. You will populate them with the appropriate logic where needed in the following sections. For more information on each listener callback method, see documentation on IUnityAdsListener API.
Interstitial display ads
To display a full-screen interstitial ad using the Advertisements API, simply initialize the SDK and use the Show function with the desired Ad Unit ID.
Interstitial ads example
In this example, you can invoke DisplayInterstitialAd from anywhere in your game you wish to show an interstitial ad.
Rewarded video ads
Rewarding players for watching ads increases user engagement, resulting in higher revenue. For example, games may reward players with in-game currency, consumables, additional lives, or experience-multipliers. For more information on how to effectively design your rewarded ads, see documentation on Ads best practices.
To reward players for completing a video ad, use the onUnityAdsFinish listener callback method’s FinishState result to check if the user finished watching the ad and should be rewarded.
Rewarded video example
Rewarded video ad buttons
Using a button to allow the player to opt in to watching an ad is a common implementation for rewarded video ads. Use the example code below to create a rewarded ads button. The ads button displays an ad when pressed, as long as ads are available. For information on configuring buttons, see Android’s documentation.
Once you’ve implemented your button, add a script with the following code, where showAdButton is a button configured in the View:
Banner ads
Ad Unit configuration
Banner ads require a specific type of dedicated banner Ad Unit.
app-ads.txt
app-ads.txt is an IAB initiative to combat fraud and create transparency in the advertising ecosystem. Be sure to implement app-ads.txt as described. Otherwise, banner demand may be significantly decreased.
Script implementation
Note: You must initialize Unity Ads before displaying a banner ad.
In your game script, import the BannerView API, then implement an IListener interface to provide callbacks to the SDK. The following script sample is an example implementation for displaying two banner ads on the screen, and buttons for testing them. For more information on the classes referenced, see the BannerView API section.
Note: This example uses a single listener for multiple banner view objects. You can also have a different listener for each banner view object.
Banner position
You can place the banner view object into your view hierarchy, just like you would any other view. This allows you to customize the position of each banner instance, or display multiple banners.
Testing
Prior to publishing your game, enable test mode by following these steps:
- From the Monetize Dashboard, select your Project.
- Select Project Settings from the navigation bar.
- Scroll down to the Test Mode section, then edit the Google Play Store.
- Select the Override client test mode checkbox, then select the Force test mode ON for all devices radio button.
Run your project and test your ads implementation.
Note: You must enable test mode before testing ads integration, to avoid getting flagged for fraud.
Источник
Integrating Unity Ads with Mediation
This guide is intended for publishers who want to use the Google Mobile Ads SDK to load and display ads from Unity Ads via mediation. It covers how to add Unity Ads to an ad unit’s mediation configuration, how to set up Automatic data collection, and how to integrate the Unity Ads SDK and adapter into an Android app.
Supported ad formats and features
The Ad Manager mediation adapter for Unity Ads has the following capabilities:
Formats | |
---|---|
Banner | |
Interstitial | |
Rewarded | |
Native | |
Features | |
Adaptive banner | |
Automatic data collection |
Requirements
- Android API level 16 or higher
- Latest Google Mobile Ads SDK
Step 1: Set up Unity ads
On the Unity Ads Dashboard, navigate to the Project tab and click the New Project button.
Fill out the form and click Add Project at the bottom of the page to add your project to Unity Dashboard.
Once your project is created, navigate to the Monetization > Placements tab of your project and take note of the Game ID.
To create a new placement, click the Add Placement button.
For additional instructions on creating an ad placement, select the tab corresponding to your preferred ad format.
Banner
Enter your desired Placement ID, select Banner as the ad format and click Create Placement.
Interstitial
Enter your desired Placement ID, select Interstitial Video as the ad format and click Create Placement.
Rewarded
Enter your desired Placement ID, select Rewarded Video as the ad format and click Create Placement.
In addition to the Game ID and Placement ID you will also need your Unity Ads API Key and Organization core ID for setting up your Ad Manager ad unit ID.
Navigate to the Ads Data Export > API Access tab of the Unity Ads Dashboard and take note of the Monetization Stats API Access Key.
Then, navigate to the Settings tab of the Unity Ads Dashboard and take note of the Organization core ID.
Step 2: Configure mediation settings for your Ad Manager ad unit
Sign in to your Ad Manager account. Navigate to Delivery > Yield groups and click the New yield group button.
Enter a unique Name for your yield group, set the Status to Active, select your Ad Format, and set the Inventory type to Mobile App. Under the Targeting > Inventory section, select the Ad Unit ID to which you want to add mediation.
Next, click the Add yield partner button.
If you already have a Yield partner for Unity Ads, you can simply select it. Otherwise, select Create a new yield partner.
Select UnityAds as the Ad network and enter a unique Name. Enable Mediation and turn on Automatic data collection and enter the API Key and Organization core ID obtained in the previous section. You don’t need to enter a Username and Password. Click Save when done.
Once the Yield partner is selected, choose Mobile SDK mediation as the Integration type, Android as the Platform, and Active as the Status. Enter the Game ID and the Placement ID obtained in the previous section and a Default CPM value.
Click Save at the bottom of the page when done.
Using rewarded ads
In the settings for your rewarded ad unit, provide values for the reward amount and reward type. Then, to ensure you provide the same reward to the user no matter which ad network is served, check the Override reward settings from third-party ad networks when using mediation box.
If you don’t apply this setting, the Unity adapter defaults to a reward of type «» (empty string) with a value of 1 . The Unity Ads SDK does not provide specific reward values for its rewarded ads.
Step 3: Import the Unity Ads SDK and adapter
Android Studio integration (recommended)
Add the following gradle dependencies with the latest versions of the Unity Ads SDK and adapter in your app-level build.gradle file:
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: Additional code required
No Additional code is required for Unity ads integration.
Step 5: Test your implementation
Test ads can be enabled from the Unity Ads dashboard in two ways.
If you want to enable test ads for all devices, navigate to the Settings > Project Settings tab of your project. Under the Test Mode section, edit the Client test mode not overridden section, check Override client test mode box, select Force test mode ON and click Save.
If you want to enable test ads only for specific devices, navigate to the Ads Data Export > Test Devices tab. Under the Test Devices section, click the Add New Device button and fill out the resulting form.
Optional steps
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.
Follow the instructions below to enable or disable personalized ads for Unity Ads.
Unity Ads provides a GDPR Compliance guide that describes both automatic and manual solutions for user consent.
The following sample code shows how to pass consent information to the Unity Ads SDK manually. 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 via the Google Mobile Ads SDK.
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.getAdapterResponse() under the following classes:
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 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-level build.gradle file.
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 calling UnityAds.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.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Источник