Tag Archives: mobile_ads_sdk

Adding SDK-less mediation to your project

We recently announced SDK-less mediation - a new way for DFP and AdMob publishers to use mediation to access additional ad networks without having to integrate and maintain multiple third-party SDKs and adapters. Today, we would like to go into more detail on how you can integrate SDK-less in your project.

With SDK-less mediation, everything is done through a single SDK, the Google Mobile Ads SDK. It is now possible to add additional ad networks server-side without having to update your apps. Also, SDK-less supports all existing mediation features including ad network optimization, live eCPM, and country-specific CPM values, so you won’t lose any of the features that you get with standard mediation.

An SDK-less network looks and feels like any other third-party mediation network in AdMob. It includes an ‘SDK-less’ suffix (see screenshot below) and has its own settings.

Supporting SDK-less Mediation

To support SDK-less ad networks, Android apps require v7.8 or higher of the Google Mobile Ads SDK for both AdMob and DFP. However, devices that have an up-to-date Google Play services already support SDK-less.

For iOS apps, v7.2.1 or higher of the Google Mobile Ads SDK is required for AdMob and v7.6.0 or higher is required for DFP. If a publisher’s app is not updated to the minimum SDK version required to support SDK-less networks, then the mediated request excludes all SDK-less networks.

In many cases, even after you migrate to the latest version of the Google Mobile Ads SDK, there may be apps that still reference older SDKs. To accommodate this, AdMob allows publishers to place both SDK adapters and SDK-less sources in a single mediation chain. Apps that don’t meet the minimum SDK requirements will ignore the SDK-less mediation sources automatically.

Ad Networks Supporting SDK-less Mediation

There are currently four ad networks that support SDK-less mediation for both banner ads and interstitial ads. The AdMob developer site for Android and iOS provides a table that lists all the AdMob mediation networks including the type of mediation and ad formats that they support. Please keep an eye on this table as there will be more ad networks supporting SDK-less in the near future.

If you have any questions regarding SDK-less mediation, feel free to contact us through our forum.

iOS Google Mobile Ads SDK 7.7.0 – now with bitcode support!

We’ve added support for bitcode in the latest release of the iOS Google Mobile Ads SDK! The Enable Bitcode setting was introduced in Xcode 7 as one of the components of app thinning - a technique to help re-optimize your app binary in the future without having to submit a new version to the App Store.

You can change this setting for your app in the project’s Build Settings. Under the Build Options section, set Enable Bitcode to Yes. Note that if you enable bitcode, all apps and frameworks in the app bundle need to include bitcode as well.

With the new release, we’ve also made some additional changes, one of which is an added dependency for the MediaPlayer framework. You will need to link this framework to your app’s binary. If you are using CocoaPods, then running a simple pod update will do the trick.

If you have any questions regarding the new iOS SDK release, feel free to contact us through our forum.

Google Mobile Ads Unity Plugin v3.0.0

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.

Streamlined Build Process

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.

Android

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.

iOS

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.

Custom IAP

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.

Ad Event Refactoring

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.

Old Ad Event New Ad Event
AdLoaded OnAdLoaded
AdFailedtoLoad OnAdFailedToLoad
AdOpened OnAdOpening
AdClosing (deprecated)
AdClosed OnAdClosed
AdLeftApplication OnAdLeavingApplication

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.

Consider your contexts when mediating

For Android developers, Context objects can be tricky. To start with, android.content.Context has a zillion subclasses, some of which are really specific (I’m looking at you, NotificationCompatSideChannelService). On top of that, there are a bunch of available calls to retrieve the current Context, all of which seem slightly different. Once you start talking about passing these objects from one part of an app to another, which happens during AdMob mediation, it can get confusing in a hurry. In order to keep things straight, engineers building Android custom events and mediation adapters need to make sure they’re handling Contexts properly.

If you’ve ever built a custom event or mediation adapter for AdMob, you’re probably familiar with these two methods:


requestInterstitialAd(Context context,
CustomEventInterstitialListener listener,
String serverParameter,
MediationAdRequest mediationAdRequest,
Bundle customEventExtras)

requestInterstitialAd(Context context,
MediationInterstitialListener listener,
Bundle serverParameters,
MediationAdRequest mediationAdRequest,
Bundle mediationExtras)

They’re from the CustomEventInterstitial and MediationInterstitialAdapter interfaces, respectively, and are used to request interstitial ads from custom events and adapters. Both include a Context parameter that can be used to retrieve information about the execution environment, query permissions, and access user preferences. In most cases, that object ends up being the Activity an app is displaying when its ad request is made (Activity is a subclass of Context), but that’s not guaranteed.

For example, consider an app that switches quickly from one Activity to another, and occasionally shows an interstitial ad during one of the transitions. Requesting a new ad in each onCreate method will likely waste resources, so offloading that work to a separate class that lives outside the Activity lifecycle is a common solution. Because that class isn’t an Activity, though, it can’t use itself as a Context, and instead must request interstitials using the Application object (another Context subclass). If the app uses custom event and adapter classes that were only tested with Activity objects, they might break!

The best practice here is to make sure to test your custom events and adapters with both Activity and Application objects prior to releasing them. A reliable custom event needs to operate the same no matter which is provided, and the same goes for adapters. If, for some reason, the SDK you’re adapting just can’t work with an Application object as the context parameter, you can always trap this using instanceof and log the error:


@Override
Public void requestInterstitialAd(Context context,
CustomEventInterstitialListener listener,
String serverParameter,
MediationAdRequest mediationAdRequest,
Bundle customEventExtras) {
if (!(context instanceof Activity)) {
Log.w(“Example”, “Context not an Activity. Returning error!”);
listener.onAdFailedToLoad(AdRequest.ERROR_CODE_INVALID_REQUEST);
}

// ... code to request an ad using the Activity context ...
}

If you have technical questions about activities, contexts, or anything else relating to the Google Mobile Ads SDK, stop by our forum.

Register now for the March 2016 Display Ads API Workshops

We're pleased to announce that we’ll be holding a series of Display Ads API Workshops in March 2016. These workshops are a half-day of tech talks, group discussions, and office hours geared toward developers who use the DoubleClick for Publishers API, Interactive Media Ads SDK, or Mobile Ads SDKs.

These API workshops are a great way for you to meet with the display ads API team and ask questions in person. The workshops are also a great opportunity for members of the community to bring their feedback directly to us, and exchange ideas and best practices with fellow developers.

The workshops will be held in the following cities:

For more information on the workshops’ agenda and a preview of our talks, please see our workshop page.

As always, if you have any questions, feel free to drop us a line on the DFP API forums, IMA SDK forums, Mobile Ads SDK forums, or the Ads Developer Google+ page.

Announcing the Google Mobile Ads API Demo apps

The Google Mobile Ads API Demo apps for Android and iOS are now available. These new apps contain advanced examples for both AdMob and DoubleClick for Publishers (DFP) that demonstrate features of the Google Mobile Ads SDK that can help you improve the user experience and maximize ad revenue. Whether you’re a new publisher or a seasoned veteran of the SDK, the API Demo apps showcase new ways to customize ad requests, experiment with multiple ad sizes, and compare AdMob and DFP technologies.

Download the API Demo apps for Android and iOS today and explore new ways to improve your integration with the Google Mobile Ads SDK!

If you have any questions regarding the new API Demo apps, feel free to contact us through our forum.

Multiple scenes and ads in Unity

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);
}
The BannerWrapper GameObject is a wrapper for a BannerView.

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

Proguard and AdMob mediation

If you’re an Android developer who uses ProGuard to post-process builds, you already know the improvements it can make to APK size and speed. Just as handy, though, is its ability to obfuscate your compiled code by stripping out debug information and renaming classes, methods, and fields to generic identifiers. It’s a great way to discourage reverse-engineering of your application. If you’re an AdMob publisher who uses mediation, however, you need to take special care when configuring ProGuard in order to avoid obfuscating some of the code used in the mediation process.

AdMob mediation needs two classes to maintain their original names in your final APK: AdUrlAdapter and AdMobAdapter. If either of those has been renamed by ProGuard, it can cause the SDK to incorrectly return “no fill” responses for the AdMob demand in your mediated ad units.

The good news is that it’s easy to avoid this problem. Just add the following two keep options to your ProGuard configuration file:


-keep class com.google.ads.mediation.admob.AdMobAdapter {
*;
}

-keep class com.google.ads.mediation.AdUrlAdapter {
*;
}

These options instruct ProGuard to avoid renaming the two classes, and to leave the names of their fields and methods unobfuscated as well. With the original names intact, the mediation system will be able to instantiate them dynamically whenever they’re needed, and your otherwise obfuscated application won’t miss out on any AdMob impressions.

The third-party networks your app mediates may also need certain classes exempted from obfuscation. Be sure to check with those networks to find out if they have recommendations for ProGuard configuration.

If you have technical questions about this (or anything else relating to the Google Mobile Ads SDK) stop by our forum.

tags: android, admob_mediation, mobile_ads_sdk

A note on ad size and mediating smart banners

Smart banners are a handy thing for publishers. You can drop an AdMob smart banner into a layout or storyboard, and it’ll stretch or squeeze itself at runtime until it’s just the right size for the device, then request an ad to match. They’re a great feature with all the extra work hidden under the hood.

If you’re building an Android mediation adapter or custom event, though, things aren’t quite as simple -- after all, you’re under that hood, too! A common rough spot for developers is retrieving a smart banner’s size. Because the Google Mobile Ads SDK uses constants to internally represent a smart banner’s height and width, the getHeight and getWidth methods of a smart banner’s AdSize will return those constants (they’re negative numbers, so they’re quite hard to miss). That means relying on calls to getHeight and getWidth to determine a smart banner’s true size isn’t a workable strategy.

So how should adapter and custom event developers calculate sizes correctly? By avoiding getHeight and getWidth, and instead asking for pixel counts using getHeightInPixels and getWidthInPixels, two other methods offered by AdSize. You can scale their return values according to the device’s metrics and end up with the same kind of DPI values returned by getWidth and getHeight for other ad sizes. Here’s a code snippet that shows how it’s done:


// Get the raw pixel counts.
int widthInPixels = size.getWidthInPixels(context);
int heightInPixels = size.getHeightInPixels(context);

// These metrics include screen density, which is what we’re after.
DisplayMetrics displayMetrics = Resources.getSystem().getDisplayMetrics();

// These are values you can send to your mediated network’s SDK.
int widthInDpi = Math.round(widthInPixels / displayMetrics.density);
int heightInDpi = Math.round(heightInPixels / displayMetrics.density);

Once you finish the math, you’ll have proper DPI values that can be sent to whichever network you’re mediating. The calls to getHeightInPixels and getWidthInPixels require a valid Context, but you can use the one provided as a parameter to the requestBannerAd methods in MediationBannerAdapter and CustomEventBanner.

Now you know the best way to gauge the size of a smart banner! Use this approach and it’ll help keep your mediation running smoothly.

If you have technical questions about this (or anything else relating to the Google Mobile Ads SDK) stop by our forum.

Handling App Transport Security in iOS 9

The rollout of iOS 9 is expected to come this Fall and will introduce a new privacy feature called App Transport Security (ATS) to enforce best practices in secure connections between an app and its back end. This change may need your action if you are developing with the Google Mobile Ads SDK and building an app against the iOS 9 SDK.

We recommend using HTTPS exclusively if you’re developing a new app. If you’re working on an existing app, we suggest using HTTPS as much as possible and creating a plan to migrate the rest of your app toward ATS compliance.

All iOS 9 devices running apps built with Xcode 7 that don’t disable ATS will be affected by this change. The following log message appears when a non-ATS compliant app attempts to serve an ad via HTTP on iOS 9:

“App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app’s Info.plist file.”

While Google remains committed to industry-wide adoption of HTTPS, there isn’t always full compliance on third party ad networks and custom creative code served via our systems. To ensure ads continue to serve on iOS9 devices for developers transitioning to HTTPS, the recommended short term fix is to add an exception that allows HTTP requests to succeed and non-secure content to load successfully.

Publishers can add an exception to their Info.plist to allow any insecure connection:


<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>

If you have any questions regarding these changes, feel free to contact us through our forum.