Integrate Unity Ads with mediation

This guide shows you how to use GMA Next-Gen SDK to load and display ads from Unity Ads using AdMob Mediation, covering bidding and 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  1
Formats
Banner
Interstitial
Rewarded
Native

Requirements

  • Android API level 24 or higher
  • [For bidding]: To integrate all supported ad formats in bidding, use Unity adapter 4.16.0.1 or higher (latest version recommended)

Step 1: Set up configurations in Unity Ads UI

Sign up or log in to Unity Ads.

Create a project

On the Unity Ads dashboard, navigate to Projects and click New.

Fill out the form and click Create to add your project.

Navigate to Unity Ads Monetization, then click Get started.

In the New Project modal, select I will use Mediation and Google Admob for Mediation Partner, then click Next.

Select the option for ad settings, then click Next.

Select your placement setup, then click Next.

Bidding

Waterfall

Fill out the form, then click Add project.

Take note of the Game ID.

Create ad units and placements

Navigate to Unity Ads Monetization > Placements, then select your project and click Add ad unit.

Enter an Ad unit name, then select your Platform and Ad format.

Bidding

Select Bidding for the Setup. Under Placement, enter the Placement name.

Take note of the Placement ID.

Waterfall

Select Waterfall for the Setup. Under Placement, enter the Placement name, GEO Tagging and Target.

Take note of the Placement ID.

Finally, click Add ad unit to save your ad unit and placement.

Locate Unity Ads Reporting API key

Bidding

This step isn't required for bidding integrations.

Waterfall

Navigate to the Unity Ads Monetization > API management and take note of the API Key in Monetization Stats API Access.

Then, navigate to the Unity Ads Monetization > Organization Settings and take note of the Organization core ID.

Update your app-ads.txt

Authorized Sellers for Apps app-ads.txt is an IAB Tech Lab initiative that helps ensure your app ad inventory is only sold through channels you've identified as authorized. To prevent a significant loss in ad revenue, you'll need to implement an app-ads.txt file. If you haven't done so already, set up an app-ads.txt file for your app.

To implement app-ads.txt for Unity Ads, see setting up app-ads.txt for the first time.

Turn on test mode

Test mode can be enabled from the Unity Ads dashboard. Navigate to Unity Ads Monetization > Testing.

You can force test mode for your app by clicking the edit button beside Google Play Store , enabling Override client test mode and selecting Force test mode ON (i.e. use test ads) for all devices.

Alternatively, you can enable test mode for specific devices by clicking Add Test Device.

Enter your test device details, then click Save.

Step 2: Set up Unity Ads demand in AdMob UI

Configure mediation settings for your ad unit

You need to add Unity Ads to the mediation configuration for your ad unit.

First, sign in to your AdMob account. Next, navigate to the Mediation tab. If you have an existing mediation group you'd like to modify, click the name of that mediation group to edit it, and skip ahead to Add Unity Ads as an ad source.

To create a new mediation group, select Create Mediation Group.

Enter your ad format and platform, then click Continue.

Give your mediation group a name, and select locations to target. Next, set the mediation group status to Enabled, and then click Add Ad Units.

Associate this mediation group with one or more of your existing AdMob ad units. Then click Done.

You should now see the ad units card populated with the ad units you selected:

Add Unity Ads as an ad source

Bidding


Under the Bidding card in the Ad Sources section, select Add ad source. Then select Unity Ads .

Click How to sign a partnership agreement and set up a bidding partnership with Unity Ads.



Click Acknowledge & agree, then click Continue.



If you already have a mapping for Unity Ads, you can select it. Otherwise, click Add mapping.



Next, enter the Game ID and Placement ID obtained in the previous section. Then click Done.



Waterfall


Under the Waterfall card in the Ad Sources section, select Add Ad Source.

Select Unity Ads and enable the Optimize switch. Enter the API Key and Organization core ID obtained in the previous section to set up ad source optimization for Unity Ads. Then enter an eCPM value for Unity Ads and click Continue.



If you already have a mapping for Unity Ads, you can select it. Otherwise, click Add mapping.

Next, enter the Game ID and Placement ID obtained in the previous section. Then click Done.


Add Unity Ads to GDPR and US state regulations ad partners list

Follow the steps in European regulations settings and US state regulations settings to add Unity Ads to the European and US state regulations ad partners list in the AdMob UI.

Step 3: Import the Unity Ads SDK and adapter

In your app-level gradle file, add the following implementation dependencies and configurations:

Kotlin

dependencies {
    implementation("com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk:0.24.0-beta02")
    implementation("com.unity3d.ads:unity-ads:4.16.5")
    implementation("com.google.ads.mediation:unity:4.16.6.0")
}

configurations.configureEach {
    exclude(group = "com.google.android.gms", module = "play-services-ads")
    exclude(group = "com.google.android.gms", module = "play-services-ads-lite")
}

Groovy

dependencies {
    implementation 'com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk:0.24.0-beta02'
    implementation 'com.unity3d.ads:unity-ads:4.16.5'
    implementation 'com.google.ads.mediation:unity:4.16.6.0'
}

configurations.configureEach {
    exclude group: 'com.google.android.gms', module: 'play-services-ads'
    exclude group: 'com.google.android.gms', module: 'play-services-ads-lite'
}

Manual integration

  1. Download the latest Unity Ads SDK (unity-ads.aar) from their GitHub repository and add it to your project.

  2. 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

To comply with Google EU User Consent Policy, you must make certain disclosures to your users in the European Economic Area (EEA), the UK, and Switzerland, and obtain their consent for the use of cookies or other local storage where legally required, and for the collection, sharing, and use of personal data for ads personalization. This policy reflects the requirements of the EU ePrivacy Directive and the General Data Protection Regulation (GDPR). You are responsible for verifying consent is propagated to each ad source in your mediation chain. Google 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 GMA Next-Gen SDK.

Java

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

Kotlin

val gdprMetaData = MetaData(this)
gdprMetaData["gdpr.consent"] = true
gdprMetaData.commit()

See Unity Ads' GDPR Compliance for more details and the values that can be provided in each method.

US states privacy laws

US 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 through a prominent "Do Not Sell My Personal Information" link on the "selling" party's homepage. The US 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 GMA Next-Gen SDK.

Java

MetaData ccpaMetaData = new MetaData(this);
ccpaMetaData.set("privacy.consent", true);
ccpaMetaData.commit();

Kotlin

val ccpaMetaData = MetaData(this)
ccpaMetaData["privacy.consent"] = true
ccpaMetaData.commit()

See Unity Ads' Consumer privacy act compliance for more details and the values that can be provided in each method.

Step 5: Add required code

Load ad with Activity context

Pass Activity context when loading Banner, Interstitial and Native ad formats. Without activity context, ad load will fail.

Step 6: Test your implementation

Enable test ads

Make sure you register your test device for AdMob and enable test mode in Unity Ads UI.

Verify test ads

To verify that you are receiving test ads from Unity Ads, enable single ad source testing in ad inspector using the Unity Ads (Bidding) and Unity Ads (Waterfall) ad source(s).

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.getAdSourceResponses() 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 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 specific error. See code for more details.