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:
A single package supporting both Android and iOS
Support for running apps in the Unity editor
Ability to create multiple banner instances
Ability to create banners of any size
Flexible ad request targeting
and much more !
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 = 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 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()
.
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 !
- Eric Leichtenschlag , Mobile Ads Developer Relations