Integrate Unity Ads with mediation

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

1 Bidding integration is in closed beta, reach out to your account manager to request access.

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

Sign up or log in to Unity Ads.

Create a project

On Unity Ads Dashboard, navigate to Projects and click Create Project.

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

Navigate to Monetization > Get started, then click Get started.

In the Project Setup modal, select I plan to use Mediation and Google Admob for Mediation Partner, then click Next.

Select your ad settings, then click Next.

Fill out the form, then click Add Project.

Take note of the Game ID.

Create an Ad Unit

Navigate to Monetization > Ad Units, then click Add Ad Unit.

Enter an Ad Unit Name, then select your Platform and Ad Format.

Android

iOS

Finally, click Create to save your ad unit.

Add a Placement

Bidding

Contact your Google account manager to create bidding placements.

Waterfall

Once the project is created, navigate to Monetization > Placements. To create a new placement, click Add Placement for your ad unit.

Fill out the necessary details and click Add Placement.

Take note of the Placement ID.

Android

iOS

Locate Unity Ads Reporting API key

Bidding

This step isn't required for bidding integrations.

Waterfall

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 AdMob ad unit ID.

Navigate to the Monetization > Setup > API Management and take note of the Monetization Stats API Access Key.

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

Turn on test mode

Test mode can be enabled from the Unity Ads dashboard. Under your project's settings, select the Testing tab.

You can force test mode for your app by clicking the edit button of each platform, checking Override client test mode and selecting Force test mode ON (i.e. use test ads) for all devices.

Android

iOS

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

Fill out the form and click Save.

Step 2: Set up Unity Ads demand in AdMob UI

Configure mediation settings for your ad unit

Android

For instructions, see step 2 in the guide for Android.

iOS

For instructions, see step 2 in the guide for iOS.

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

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

Step 3: Import the Unity Ads SDK and adapter

OpenUPM-CLI

If you have OpenUPM-CLI installed, you can install the Google Mobile Ads Unity Ads Mediation Plugin for Unity to your project by running the following command from your project's root directory:

openupm add com.google.ads.mobile.mediation.unityads

OpenUPM

In your Unity project editor, select Edit > Project Settings > Package Manager to open the Unity Package Manager Settings.

Under the Scoped Registries tab, add OpenUPM as a scoped registry with the following details:

  • Name: OpenUPM
  • URL: https://package.openupm.com
  • Scope(s): com.google

OpenUPM Details

Then, navigate to Window > Package Manager to open the Unity Package Manager and select My Registries from the drop-down menu.

Unity Registries

Select the Google Mobile Ads Unity Ads Mediation package and click Install.

Install from OpenUPM

Unity Package

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 find the GoogleMobileAdsUnityAdsMediation.unitypackage file you downloaded. Make sure that all the files are selected and click Import.

Import from Unity

Then, select Assets > External Dependency Manager > Android Resolver > Force Resolve. The External Dependency Manager library will perform dependency resolution from scratch and copy the declared dependencies into the Assets/Plugins/Android directory of your Unity app.

Force Resolve

Step 4: Implement privacy settings on Unity Ads SDK

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

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 (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 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 3.12.2

Version 3.12.1

Version 3.12.0

Version 3.11.1

Version 3.11.0

Version 3.10.0

Version 3.9.1

Version 3.9.0

Version 3.8.0

Version 3.7.1

Version 3.7.0

Version 3.6.1

Version 3.6.0

Version 3.5.0

Version 3.4.1

Version 3.4.0

Version 3.3.0

Version 3.2.1

Version 3.2.0

Version 3.1.0

Version 3.0.1

Version 3.0.0

Version 2.7.2

Version 2.7.1

Version 2.7.0

Version 2.6.0

Version 2.5.1

Version 2.5.0

Version 2.4.7

Version 2.4.6

Version 2.4.5

Version 2.4.4

Version 2.4.3

Version 2.4.2

Version 2.4.1

Version 2.4.0

Version 2.3.0

Version 2.2.0

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.