Today we're announcing the release of Mediation Test Suite Beta. Mediation Test Suite is a lightweight SDK that enables Google AdMob publishers to easily test mediation ad network integrations without having to make changes in the AdMob UI, saving you and your developers time. It is available on Android, iOS, and Unity.
Mediation Test Suite allows you to:
Integrating Mediation Test Suite is easy -- once you have the SDK imported, it can be launched with just a single line of code. All you need is your AdMob app ID.
On Android, the launch code looks like this:
import com.google.android.ads.mediationtestsuite.MediationTestSuite; ... String appId = "YOUR-ADMOB-APP-ID"; MediationTestSuite.launch(MainActivity.this, appId);
On iOS, all that's required is importing the correct header and launching the Test Suite:
#import "GoogleMobileAdsMediationTestSuite.h" ... NSString* appId = @"YOUR-ADMOB-APP-ID" [GoogleMobileAdsMediationTestSuite presentWithAppID:appId onViewController:self delegate:nil];
Unity is just as simple, but please note that you need to use the appropriate app ID for your platform:
using GoogleMobileAdsMediationTestSuite.Api; ... #if UNITY_ANDROID string appId = "YOUR-ANDROID-ADMOB-APP-ID"; #elif UNITY_IPHONE string appId = "YOUR-iOS-ADMOB-APP-ID"; #else string appId = ""; #endif MediationTestSuite.Show(appId);
Including Mediation Test Suite in production builds is optional
You are not required to keep the Mediation Test Suite library in the production release of your app; however, you may choose to leave it in and hide it behind a debug gesture. Doing so enables you to launch Mediation Test Suite within your production build.
You can find more information about how to use Mediation Test Suite in the developer guide (Android | iOS | Unity). Remember that Mediation Test Suite is a beta product, so if you have any questions or feedback, please contact us on the developer forum.
- Jon Weisbaum, Mobile Ads Developer Relations
We recently launched v3.3.0 of the Google Mobile Ads Unity Plugin with support for ad position offsets and Unity 5.6 compatibility. The updated v3.3.0 Unity package is available for download from the Google Mobile Ads Unity Plugin GitHub repository.
Version 3.3.0 of Google Mobile Ads Unity Plugin adds the ability to specify an x and y position for both BannerView and NativeExpressAdView objects. To position ad views outside of the existing AdPosition values, provide x and y offsets instead of an AdPosition when instantiating an ad view, as shown below.
BannerView
NativeExpressAdView
AdPosition
BannerView bannerView = new BannerView(adUnitId, AdSize.SmartBanner, 50, 50);
The code snippet above creates a BannerView offset from the top-left corner of the screen by 50 density independent pixels in the x and y axis. NativeExpressAdView positions can be offset in the same manner, as shown below.
NativeExpressAdView nativeExpressAdView = new NativeExpressAdView( adUnitId, new AdSize(320, 150), 50, 50);
Although Unity 5.6 is still in beta, the latest version of the Google Mobile Ads Unity plugin includes changes to be fully compatible with the upcoming release.
In addition to the new features outlined above, it is recommended to update to the latest version of the Google Mobile Ads plugin to take advantage of stability and bug fixes. The source code and a sample app for the plugin are available in our GitHub repo, as is the full changelog for this release. If you have any questions about Unity integration, you can reach us on our developer forum.
We recently launched v3.0.7 of the Google Mobile Ads Unity Plugin. The updated v3.0.7 Unity package is available for download from the Google Mobile Ads Unity Plugin GitHub repository.
This release introduces support for Native Ads Express. With Native Ads Express, you can create CSS templates that define how ads are presented in your app (things like image sizes, fonts, colors, and so on). These CSS templates are used to generate ad creatives that complement the native look and feel of your app. You can find more information on integrating Native Ads Express into Unity applications in our developer docs.
The v3.0.7 release resolves compatibility issues with the IL2CPP scripting backend and the Google Mobile Ads Unity Plugin. This allows the use of the the IL2CPP scripting backend, a high-performance alternative to the Mono virtual machine and AOT compiler, in Unity applications with the Google Mobile Ads SDK.
The source code and a sample app for the plugin are available in our GitHub repo, as is a changelog for this release. If you have any questions about Unity integration, you can reach us on our developer forum.
Registering for banner and interstitial ad events is a handy way for Unity developers using the Google Mobile Ads Unity Plugin to track ad lifecycle events -- things like when an ad is loaded or when an ad click causes the app to be backgrounded. For Unity developers deploying to the Android platform, though, it's important to be aware that ad event handler methods are not invoked on the main thread. As a consequence, Unity methods that must be called on the main thread cannot be executed within ad event handler methods.
Consider the following example:
AudioSource audio = GetComponent<AudioSource>(); ... public void HandleInterstitialClosed(object sender, EventArgs args) { audio.mute = false; }
The code above, which modifies the volume of an audio source from within an ad event handler method, results in the following error:
ArgumentException: set_volume can only be called from the main thread
To get around this, we recommend setting a flag when an event happens, and polling for a state change within the Update() method of your Unity script.
Update()
For actions required to be performed on the main thread after showing an ad, set a flag on the OnAdClosed ad event. The update method can poll the value of this flag and perform actions as necessary. The code below illustrates how to implement this approach.
OnAdClosed
private bool interstitialClosed; void Start() { InterstitialAd interstitial = new InterstitialAd("YOUR_AD_UNIT_ID"); interstitial.OnAdClosed += HandleInterstitialClosed; interstitialClosed = false; ... } void Update() { if (interstitialClosed) { // Perform actions here. audio.mute = false; } } public void HandleInterstitialClosed(object sender, EventArgs args) { interstitialClosed = true; }
If you have any questions about Unity integration, you can reach us on our forum. You can also find our quick-start guide here. Remember that you can also find us on Google+, where we have updates on all of our Google Ads developer products.
- Ram Parameswaran, Mobile Ads Developer Relations
Today we're launching version 3.0.0 of the Google Mobile Ads Unity Plugin. The updated Unity package is available for download on our GitHub repo.
With the v3.0.0 release of the Google Mobile Ads Unity plugin, the process for generating both Android and iOS projects no longer requires additional setup.
The Google Play Services library project no longer has to be included within your Unity project. Instead, the necessary Google Play services client libraries are automatically copied into Unity projects at build time. This functionality is provided via the Unity JarResolver library (linked on our GitHub repo). This change decreases app size and fixes compatibility issues with other Unity plugins that use Google Play services, such as the Google Play Games plugin.
The Google Mobile Ads Unity plugin now uses CocoaPods to deploy the Google Mobile Ads SDK into the iOS project generated by Unity. The Google Mobile Ads Unity plugin will also configure all necessary build settings for the iOS project.
This release of the Google Mobile Ads Unity Plugin also brings support for non-default in-app purchases. The non-default purchase flow gives developers full control over the implementation of the billing flow, while allowing for purchase of both consumable and non-consumable products. Steps on how to integrate non-default in-app purchases into your Unity application can be found on our Game Developers guide.
This release includes a refactoring of ad events for both banners and interstitials. Take note of the following changes and update projects written against past versions of the Google Mobile Ads Unity plugin.
The source code and a sample app for the plugin are available on our GitHub repo, as is a changelog for this release. If you have any questions about Unity integration, you can reach us on our forum. Remember that you can also find us on Google+, where we post updates on all of our Google Ads developer products.
When developing with AdMob in Unity, it is a common practice to make your banner ads persist across multiple scenes. This blog post will highlight best practices to accomplish this with the Google Mobile Ads Unity Plugin.
The most straightforward approach is to link the lifecycle of ads to that of the scenes they’re displayed in. When transitioning from one scene to another, existing ads are destroyed before leaving the first scene. New ads can then be created and displayed in the next scene.
The downside of this approach is that every scene transition would result in a new banner request. This may not be desirable if scene transitions are frequent and occur quickly.
An alternative is to use a GameObject as a wrapper for banners or interstitials. By default, each GameObject in a scene will be destroyed once the new scene is loaded (unless you use additive scene loading). However, you can make a GameObject survive across scenes by marking it with DontDestroyOnLoad. You can then use the GameObject.Find method to obtain references to the wrapper GameObject from scripts in other scenes.
Here is an example of how to use a GameObject to wrap banner ads:
// FirstSceneScript.cs void Start() { // Create a wrapper GameObject to hold the banner. GameObject myGameObject = new GameObject("myBannerAdObject"); myGameObject.AddComponent<BannerWrapper>(); // Mark the GameObject not to be destroyed when new scenes load. DontDestroyOnLoad(myGameObject); }
// BannerWrapper.cs using System; using UnityEngine; using GoogleMobileAds; using GoogleMobileAds.Api; public class BannerWrapper : MonoBehaviour { public BannerView bannerView; void Start() { bannerView = new BannerView( "your_ad_unit_id", AdSize.SmartBanner, AdPosition.Bottom); AdRequest request = new AdRequest.Builder().Build(); bannerView.LoadAd (request); bannerView.Show(); } }
In SecondSceneScript.cs, which is attached to the second scene, you can find a GameObject by name, get the BannerWrapper component, and access the BannerView:
// SecondSceneScript.cs void Start () { GameObject myGameObject = GameObject.Find("myBannerAdObject"); BannerWrapper bannerWrapper = myGameObject.GetComponent(); bannerWrapper.bannerView.Hide(); }
By managing your ads efficiently and seamlessly across scenes, you are sure to provide a better ad experience for your users. If you have any questions about Unity integration, you can reach us on our forum. You can also find our quick-start guide linked here. Remember that you can also find us on Google+, where we have updates on all of our Google Ads developer products.
We’re excited to announce the v2.3.0 release of the Google Mobile Ads Unity Plugin! The new release brings support for AdMob in-app purchase ads to the Unity game engine. You can grab the updated Unity package on GitHub.
In-app purchase (IAP) ads are interstitial ads that display offers for your in-app products. They allow users to make purchases directly from within your app as part of your normal ad flow.
Note: The plugin currently only supports IAP ads on Android. iOS support is not yet available.
Before integrating IAP ads into your app, make sure you’ve set up an IAP house ad campaign and created an IAP house ad. You should also install the plugin as explained in the AdMob Unity Quick Start guide.
Once you’ve set up your campaign, there are five steps to integrate IAP ads:
AndroidManifest.xml
<!--<uses-permission android:name="com.android.vending.BILLING"/> -->
IInAppPurchaseHandler
OnInAppPurchaseFinished
result.FinishPurchase()
IsValidPurchase
AndroidPublicKey { get; }
InterstitialAd.SetInAppPurchaseHandler
That’s it!
If you have any questions, please drop by our forum.
We have launched the Google Mobile Ads Unity Plugin v2.2.1. The updated v2.2.1 Unity package is available for download on GitHub here.
Google Mobile Ads Unity Plugin v2.2.1 introduces support for additional banner position locations. The full list of banner positions is as follows:
The additional positions are specified by setting the AdPosition value when instantiating a bannerView:
//Create a banner at the top-right of the screen. BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.TopRight);
With the v7.0.0 release, the iOS Ads SDK became a module framework and Google Mobile Ads Unity Plugin v2.2.1 complies with this change. For modules to work, you must enable them in the project build settings. Search for "modules", and set Enable Modules to YES. The Link Frameworks Automatically option should be set to YES as well.
Enable Modules
YES
Link Frameworks Automatically
Unity 5.0 has moved out of beta and brings with it support for Automatic Reference Counting (ARC) for iOS. v2.2.1 of the Unity plugin takes advantage of ARC with no additional changes in project settings or code.
The source code and a sample app for the plugin are available on our GitHub repo. A changelog for this release is listed here. If you have any questions about Unity integration, you can reach us on our forum. Remember that you can also find us on Google+, where we have updates on all of our Google Ads developer products.
Today, we’re delighted to announce the launch of the Google Mobile Ads Unity Plugin v2.1, now with interstitial ads. You can start playing around with the latest code by grabbing the v2.1 Unity package on GitHub.
There are four steps required to integrate interstitial ads:
InterstitialAd
The first three steps can be performed at the same time, and can even live in its own helper function:
public InterstitialAd CreateAndLoadInterstitial() { // Initialize an InterstitialAd. InterstitialAd interstitial = new InterstitialAd("MY_AD_UNIT_ID"); // Register for ad events. interstitial.AdLoaded += delegate(object sender, EventArgs args) {}; interstitial.AdFailedToLoad += delegate(object sender, AdFailToLoadEventArgs args) {}; interstitial.AdOpened += delegate(object sender, EventArgs args) {}; interstitial.AdClosing += delegate(object sender, EventArgs args) {}; interstitial.AdClosed += delegate(object sender, EventArgs args) {}; interstitial.AdLeftApplication += delegate(object sender, EventArgs args) {}; // Load the InterstitialAd with an AdRequest. interstitial.LoadAd(new AdRequest.Builder().Build()); }
You should wait to show the interstitial until a good stopping point in your app, for example when the user finishes a level in your game. Remember to check that the interstitial has finished loading before you show it:
// Call this when a level finishes. public void LevelFinished() { if (interstitial.isLoaded()) { interstitial.Show(); } }
Keep in mind that an interstitial is a one-time use object. Once the interstitial is closed, you can dispose of the object and prepare another one. This can be implemented directly in the AdClosed event.
AdClosed
interstitial.AdClosed += delegate(object sender, EventArgs args) { interstitial.Destroy(); interstitial = CreateAndLoadInterstitial(); };
In this release, we also changed our ad events to be of type EventHandler instead of Action for both BannerView and InterstitialAd. This means your callback methods now take an object representing the event sender, and an EventArgs:
object
interstitial.AdLoaded = delegate(object sender, EventArgs args) { print(“Interstitial Loaded”); };
The only event with special event args is AdFailedToLoad. It passes an instance of AdFailedToLoadEventArgs with a Message describing the error.
AdFailedToLoad
Message
interstitial.AdFailedToLoad = delegate(object sender, AdFailedToLoadEventArgs args) { print("Interstitial Failed to load: " + args.Message); };
The source code as well as a sample app for the plugin is available on our googleads-mobile-plugins GitHub repo. If you have any questions about Unity integration, you can reach us on our forum. Remember that you can also find us on Google+, where we have updates on all of our Google Ads developer products.
- Eric Leichtenschlag, Mobile Ads Developer Relations
Calling all Unity app developers! We are excited to announce the launch of version 2.0 of the Google Mobile Ads Unity Plugin. The new version comes with a completely rewritten, but much more flexible, API. It includes the following new features:
Taking a closer look at how to integrate the plugin, a typical banner request in v2.0 looks like this:
BannerView bannerView = new BannerView( "YOUR_AD_UNIT_ID", AdSize.Banner, AdPosition.Top); AdRequest request = new AdRequest.Builder().Build(); bannerView.LoadAd(request);
For custom banner sizes, simply pass in an AdSize object into the BannerView constructor:
AdSize
AdSize adSize = new AdSize(250, 250); BannerView bannerView = new BannerView( "YOUR_AD_UNIT_ID", adSize, AdPosition.Top);
Want to pass additional targeting parameters? No problem! Set your custom targeting when building the AdRequest:
AdRequest
AdRequest request = new AdRequest.Builder() .AddTestDevice(AdRequest.TestDeviceSimulator) .AddTestDevice("0123456789ABCDEF0123456789ABCDEF") .AddKeyword("unity") .SetGender(Gender.Male) .SetBirthday(new DateTime(1985, 1, 1)) .TagForChildDirectedTreatment(true) .Build();
Listening for ad events is also extremely straightforward. Register for the callbacks you care about:
bannerView.AdLoaded += HandleAdLoaded; bannerView.AdFailedToLoad += HandleAdFailedToLoad; bannerView.AdOpened += HandleAdOpened; bannerView.AdClosing += HandleAdClosing; bannerView.AdClosed += HandleAdClosed; bannerView.AdLeftApplication += HandleAdLeftApplication; … public void HandleAdLoaded() { print("HandleAdLoaded event received."); }
You can also manage the lifecycle of each BannerView by calling show(), hide(), or destroy().
show()
hide()
destroy()
To get access to these awesome features, check out the source code. Also stay tuned for upcoming support for interstitial ads.
If you have any feature requests or bug reports against the plugin, track it! If you have questions about how to use the plugin, speak up! And if you just want the latest news on what’s going on in the wonderful world of Google Ads, circle us!