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
Banners
Interstitials
Rewarded Video
Rewarded Video (new APIs)
Native Ads - Custom Rendering
Features
Smart Banners
Automatic data collection

Requirements

  • Android API level 16 or higher
  • Latest Google Mobile Ads SDK

Step 1: Set up Unity ads

Sign up or log in to 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.

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 Video

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 video ads

In the settings for your rewarded video 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 video ads.

Step 3: Import the Unity Ads SDK and adapter

Add the following gradle dependencies with the latest versions of the Unity Ads SDK and adapter in your app-level build.gradle file:

repositories {
    jcenter()
}

...
dependencies {
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.gms:play-services-ads:19.5.0'
    implementation 'com.google.ads.mediation:unity:3.4.8.0'
}
...

Manual integration

Download the latest Unity Ads SDK (unity-ads-x.y.z.aar) from Bintray and add it to your project.

Download the latest version of the Unity adapter from Bintray, 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

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.

MetaData gdprMetaData = new MetaData(this);
gdprMetaData.set("gdpr.consent", true);
gdprMetaData.commit();

Unity Ads Android Mediation Adapter Changelog

Next Version

  • Add adaptive banner support

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.