admob

Banners I

Google AdMob Ads banners use a small portion of the screen to entice users to "click through" to a richer, full-screen experience such as a website or app store page. This guide shows you how to enable your app to serve a banner ad.
To display banners in your Android app, simply add a com.google.ads.AdView to your UI.

Adding a com.google.ads.AdView

Android apps are composed of View objects, Java instances the user sees as text areas, buttons and other controls. AdView is simply another View subclass displaying small HTML5 ads that respond to user touch.

Like any View, an AdView may be created either purely in code or largely in XML.

The five lines of code it takes to add a banner:

  • Import com.google.ads.*
  • Declare an AdView instance
  • Create it, specifying a unit ID—your AdMob publisher ID
  • Add the view to the UI
  • Load it with an ad

The easiest place to do all this is in your app's Activity.

import com.google.ads.*;

public class BannerExample extends Activity {
  private AdView adView;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Create the adView
    adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);

    // Lookup your LinearLayout assuming it's been given
    // the attribute android:id="@+id/mainLayout"
    LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);

    // Add the adView to it
    layout.addView(adView);

    // Initiate a generic request to load it with an ad
    adView.loadAd(new AdRequest());
  }

  @Override
  public void onDestroy() {
    if (adView != null) {
      adView.destroy();
    }
    super.onDestroy();
  }
}
Warning: Make sure you're in test mode during development to avoid being disabled for clicking your own ads. See the  Additional Controls guide for more details on enabling test ads.

You can download an example project containing this code here.

Create your banner in XML

Rather than creating your AdView in Java, it's also possible to set one up entirely in XML. To do so simply:

  • Incorporate the SDK into your app
  • Define a com.google.ads.AdView in res/layout/main.xml, specifying it should immediately load an ad by using the ads:loadAdOnCreateattribute.
  • Alternately, instead of forcing the AdView to load an ad immediately, Look up the AdView as a resource at runtime and tell it to request an ad.

Defining a com.google.ads.AdView

The easiest way to incorporate an ad is to simply define your AdView as you would any other part of your res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
  <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="MY_AD_UNIT_ID"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                         ads:loadAdOnCreate="true"/>
</LinearLayout>

As usual you must replace MY_AD_UNIT_ID with your AdMob publisher ID. You must also add your own device ID in the ads:testDevices attribute to get test ads on your device. Note the inclusion of the ads namespace referenced in specifying adUnitId and adSize. This code will immediately attempt to load an ad as soon as the AdView is created by Android's layout engine.

Lookup and Load

If you have a need to control the AdRequest used to load an ad in your application, you can remove the ads:loadAdOnCreate="true" line from the above code. Instead, you will want to look up the AdView as a resource via findViewById and instruct it to loadAd:

import com.google.ads.*;

public class BannerExample extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Look up the AdView as a resource and load a request.
    AdView adView = (AdView)this.findViewById(R.id.adView);
    adView.loadAd(new AdRequest());
  }
}

You can download an example project containing this code here.

The Result

When you now run your app you should see a banner at the top of the screen:

Note: The very first time AdMob sees your publisher ID it may take up to two minutes to receive an ad. This initial two minute lag will recur every time the ID goes unused for 24 hours. Warning: All new Android apps created after October 14, 2011 will require an  AdMob SDK that was released on or after May 11, 2011. This corresponds to version 4.1.0+ for Android. If you downloaded the library from our  official download site, then you're already set. Otherwise you may have an old version of the AdMob SDK that was released prior to May 11, 2011, and your new app will not receive any ad impressions until you update your SDK.

Proceed to the next guide to learn more about banner ads.

Banners II

In this guide, we show you more ways to control banner ad properties.

  1. Banner Sizes
  2. Ad Refresh
  3. com.google.ads.AdRequest
    1. AdRequest.addTestDevice | AdRequest.setTestDevices
    2. Targeting
  4. com.google.ads.AdListener

Banner Sizes

Google AdMob Ads supports three tablet-only banner sizes in addition to the 320x50 shown on phones:

Size (WxH) Description Availability AdSize Constant
320x50 Standard Banner Phones and Tablets BANNER
300x250 IAB Medium Rectangle Tablets IAB_MRECT
468x60 IAB Full-Size Banner Tablets IAB_BANNER
728x90 IAB Leaderboard Tablets IAB_LEADERBOARD
See table Smart Banner Phones and Tablets SMART_BANNER

The SDK will request whatever size the requesting AdView was instantiated with. If there isn't enough space on the device's screen to display the ad, nothing will be shown.

Ad Refresh

Banners auto-refresh if a refresh rate has been specified in your AdMob account on the server and may be programmatically refreshed by loading a new request.

com.google.ads.AdRequest

Before being passed to AdView.loadAd an AdRequest may be customized to allow Google to better target ads.

AdRequest.addTestDevice | AdRequest.setTestDevices

You can use these properties to to specify a device or Set of devices that will receive test ads. You should utilize this property during development to avoid generating false impressions. To verify that you've integrated the SDK correctly, add your test device, run your application, and click on the displayed test ad.

AdRequest request = new AdRequest();

request.addTestDevice(AdRequest.TEST_EMULATOR);
request.addTestDevice("E83D20734F72FB3108F104ABC0FFC738");    // My T-Mobile G1 test phone

logcat will print the device's MD5-hashed ID for convenience, for example: 
   To get test ads on this device, call adRequest.addTestDevice("E83D20734F72FB3108F104ABC0FFC738");

Targeting

Location and demographic targeting information may also be specified. Out of respect for user privacy, Google asks that you only specify location and demographic data if that information is already used by your app.

AdRequest request = new AdRequest();

request.setGender(AdRequest.Gender.FEMALE);
request.setLocation(location);
request.setBirthday("19850101");

where the user's location is obtained by a suitable method.

com.google.ads.AdListener

You may optionally track ad lifecycle events like request failures or "click-through" by implementing com.google.ads.AdListener in an object you pass toAdView.setAdListener.

public interface AdListener {
  public void onReceiveAd(Ad ad);
  public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode error);
  public void onPresentScreen(Ad ad);
  public void onDismissScreen(Ad ad);
  public void onLeaveApplication(Ad ad);
}

This interface may be implemented by your activity or any other object:

import com.google.ads.*;

public class BannerExample extends Activity implements AdListener {
}

and then passed to the Ad:

adView.setAdListener(this);
public void onReceiveAd(Ad ad)
Sent when  AdView.loadAd has succeeded.
public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode error)
Sent when  loadAd has failed, typically because of network failure, an application configuration error, or a lack of ad inventory. You may wish to log these events for debugging:
@Override
public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode errorCode) {
  Log.d(MY_LOG_TAG, "failed to receive ad (" + errorCode + ")");
}
public void onPresentScreen(Ad ad)
Called when an  Activity is created in front of your app, presenting the user with a full-screen ad UI in response to their touching ad.
public void onDismissScreen(Ad ad)
Called when the full-screen  Activity presented with  onPresentScreen has been dismissed and control is returning to your app.
public void onLeaveApplication(Ad ad)
Called when an  Ad touch will launch a new application.

You can download an example project containing a sample AdListener here.

Interstitials

Banners are small ads that when touched typically take the user to some form of full-screen in-app browsing experience.

Interstitials, on the other hand, immediately present rich HTML5 experiences or "web apps" at natural app transition points such as launch, video pre-roll or game level load. Web apps are in-app browsing experiences with a simple close button rather than any navigation bar—the content provides its own internal navigation scheme.

The richer, more immersive nature of these ads makes them more expensive and subject to impression constraints.

 

Interstitial ads are supported in the iOS and Android SDKs.

InterstitialAd

The richer, more heavyweight nature of InterstitialAd is reflected by its definition not as a View but rather an Object requiring more distinct instantiation, load and display steps.

Usage is nevertheless very similar to AdView:

  • Import com.google.ads.*
  • Declare the instance
  • Create it, specifying an AdMob Publisher ID distinct from any used for banners

Once again, the easiest place to do this is somewhere in your app’s Activity.

import com.google.ads.*;

public class BannerExample extends Activity implements AdListener {

  private InterstitialAd interstitial;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Create the interstitial
    interstitial = new InterstitialAd(this, MY_INTERSTITIAL_UNIT_ID);

    // Create ad request
    AdRequest adRequest = new AdRequest();

    // Begin loading your interstitial
    interstitial.loadAd(adRequest);

    // Set Ad Listener to use the callbacks below
    interstitial.setAdListener(this);
  }

  @Override
  public void onReceiveAd(Ad ad) {
    Log.d("OK", "Received ad");
    if (ad == interstitial) {
      interstitial.show();
    }
  }
}

Here we implement AdListener and immediately show the interstitial upon callbacks to onReceiveAd(). See the Intermediate guide for further details on usingAdListener. Alternatively, you can hold onto the interstitial until you're ready to display it, checking with isReady().

Once shown, the interstitial takes over the screen until the user dismisses it, at which point control returns to your app.

Note: The timeout for an interstitial ad request is five seconds. This timeout pertains to the socket connection with the server, and has no relations to the display duration of the interstitial ad.

Download the example project.

Smart Banners

Smart Banners are new ad units (as of v6.0.0) that will render screen-wide banner ads on any screen size across different devices in either orientation. Smart Banners help deal with increasing screen fragmentation across different devices by "smartly" detecting the width of the phone in its current orientation, and making the ad view that size.

To use Smart Banners, you will need to use one of the following ad size constants:

  • SMART_BANNER (Android)
  • kGADAdSizeSmartBannerPortrait or kGADAdSizeSmartBannerLandscape (iOS)

In portrait mode on phones, this will make the ad view either 320x50 or 360x50 in size, depending on whether the device is widescreen. In landscape mode on phones, this will make the ad view anywhere from 480x32 to 682x32 depending on the height of the device.

When an image ad won't take up the entire allotted space for the banner, we'll center the image and use a hexagonal textile filler (see image) to fill up the remaining space. Note that AdSense backfill ads will be centered and have "transparent" filler.

For a full set of supported sizes and what kind of ads will appear, see the table below.

Size Where it'll appear Text ads? Image ads?
320x50 iPhones and most Android phones in Portrait Yes Yes
360x50 Android widescreen devices in Portrait Yes Yes, with 20px fill on each side
480x32 iPhones in Landscape Yes No
533x32, range of sizes from 480x32 to 682x32 Android devices in Landscape Yes No
768x90 iPads in Portrait Yes Yes
1024x90 iPads in Landscape Yes Yes, centered with 150px fill on each side
800x90 Android tablets in Portrait Yes Yes, centered with 36px fill on each side
1280x90 Android tablets in Landscape Yes Yes, centered with 276px fill on each side
600x90 Kindle Fire in Portrait Yes No
1024x50 Kindle Fire in Landscape Yes No

Note: Most mediation ad networks do not yet support Smart Banners—check with the particular network you plan to use.

Ad Network Mediation - Publisher Instructions

See this article for a walk-through of what mediation is and how to use the AdMob Mediation UI. Then, continue reading this page for instructions on how to add mediation code into your app.

Mediation is available for iOS and Android.

<table class="columns"
  1. Adding the Mediation SDK to your project
    1. 1. Integrate AdMob ads
    2. 2. Add network adapters and SDKs
    3. 3. Configure ad networks in AndroidManifest.xml
    4. 4. Convert AdMob into mediation placement
      1. a) For banner placements
      2. b) For interstitial placements
  1. Optional setup
    1. 5. Specify additional request parametersoptional
    2. 6. Set up an ad listeneroptional
    3. 7. Implement custom eventsoptional

Adding the Mediation SDK to your project

1. Integrate AdMob ads

Follow the same instructions used for integrating AdMob ads into your application. To integrate non-interstitial ads (banner size, leaderboard size, and so on), follow the fundamental instructions. To integrate interstitial ads (full-screen ads that take over the screen), follow the advanced instructions.

Once you’ve followed these integration instructions, you’ll make a few modifications described below to change your AdMob ad placement into a mediation placement that can show ads from multiple networks.

2. Add network adapters and SDKs

You're now ready to download and add to your project the adapters and SDKs of all the ad networks you'd like to serve ads from (AdMob is already included in the Mediation SDK). You can find links to them on the ad network mediation page.

To add the downloaded network adapters/SDKs in Eclipse, right click on your project and select Properties. Then add all the JAR files to your Java Build Path.

Note: You may consider integrating adapters and SDKs from networks that you’re not currently using but might use in the future. If you do this, you’ll be able to start serving ads from these networks simply by making a configuration change on mediation.admob.com (without requiring a code change to your app). Weigh this against the increase in app binary size that each additional SDK will add.

3. Configure ad networks in AndroidManifest.xml

You now need to add entries to your AndroidManifest.xml as required by each ad network you intend to use. Instructions from each network can be found from the ad network mediation page. Follow the parts of these instructions related to modifying your AndroidManifest.xml file.

Note that you only need to modify your manifest, and that there is no need to follow the networks' instructions for creating ad views or setting up listeners. The AdMob Mediation SDK will invoke each ad network's adapters and SDKs as necessary to create ads. Further below you'll see how to set up Mediation listeners that notify you of ad events for all of your networks.

4. Convert AdMob into mediation placement

The final mandatory step is to change your AdMob ad placement into a mediation placement by modifying a few parameters.

  1. a) For banner placements (including tablet sizes)
  2. b) For interstitial placements
a) For banner placements
Make the following change to your  AdView:

Specify your Mediation ID instead of your AdMob site ID in the constructor of your AdView. Your Mediation ID can be found on the settings page of the mediation placement you’ve created:

You might instantiate your AdView in this way, for example:

AdView adView = new AdView(this, AdSize.BANNER, "e123456789012345");
where  e123456789012345 is your Mediation ID.

Note: AdMob Ad Network Mediation does not fully support Smart Banners currently.

Load the ad exactly as you would load an AdMob ad. Make sure to put the adView into your layout by calling

layout.addView(adView);
where  layout is a reference to your layout.

You would then load an ad by calling adView.loadAd(new AdRequest());

Alternatively, you can specify your ad view in an XML layout.

b) For interstitial placements
  1. Specify your Mediation ID instead of your AdMob site ID in the constructor of your InterstitialAd. You might instantiate your InterstitialAd like this, for example:

    interstitial = new InterstitialAd(this, "e987654321098765");
    interstitial.setAdListener(this);
  2. Load the interstitial exactly as you would load an AdMob interstitial, for example:

    interstitial.loadAd(new AdRequest());

  3. Implement a listener to be notified when the ad has fully loaded so that you can then show it. Alternatively, you can call the isReady() method on yourInterstitialAd to poll for whether the ad is ready to be displayed.

    public class MyActivity extends Activity implements AdListener {
       private InterstitialAd interstitial;
       [ . . . ]
    public void onReceiveAd(Ad ad) {
         // Be sure to check that it is an InterstitialAd that triggered this
         // callback. Also, if there are multiple InterstitialAds, make sure
         // it is the correct one.
         if (ad == interstitial) {
           // For best performance, make sure you are not performing
           // processor-intensive or media-intensive operations while showing
           // interstitial ads.
           interstitial.show();
         }

    OR

    /*Placed when a user is at a natural stopping point, such as in between levels of a game*/
    if (interstitial.isReady()) {
        interstitial.show();
    }

    Note: Latency can be substantial when mediating interstitial ads. It can take a second or two for each network's request to fail. When a request succeeds, it can then take five seconds or more to fully load the graphical or video assets. Speed will differ on a carrier connection versus a wifi connection. For this reason, we recommend fetching an interstitial early on, and holding on to the interstitial so that it can be displayed at an appropriate time. We do not recommend trying to mediate an interstitial ad at app-open time, and putting users through a long wait screen as the interstitial tries to load.

Back to top

Optional setup

5. (optional) Specify additional request parameters

You can optionally add the user's location, gender, and birthday to your AdRequest. These are not required, but can be used by networks to serve more finely targeted ads.

We provide methods for setting birthday and location, and a property for setting gender. These will be passed along to all networks that accept them. Here is an example:

request.setGender(AdRequest.Gender.FEMALE);
request.setLocation(location);
request.setBirthday(new Date(85,0,1)); /*January 1, 1985*/

Some networks also support other request parameters that are specific to their network. You can specify these by using the setNetworkExtras() method of the AdRequest. The setNetworkExtras() method receives an instance of one of the "extras" classes below.

Each network defines its own extras class. The following table shows the names of these classes for some of the networks. Consult the Javadoc for each class and the ad network's SDK documentation for more details on each class.

Ad Network Additional-parameters class
Google AdMob com.google.ads.mediation.admob.AdMobAdapterExtras
Millennial Media com.google.ads.mediation.millennial.MillennialAdapterExtras
InMobi com.google.ads.mediation.inmobi.InMobiAdapterExtras

For example, both Millennial Media and InMobi allow specifying the income of the user to provide more relevant ads. In order to make the mediation framework pass an income when requesting an ad from these networks, you could use the following code:

import com.google.ads.AdRequest;
import com.google.ads.AdView;
import com.google.ads.mediation.inmobi.InMobiAdapterExtras;
import com.google.ads.mediation.millennial.MillennialAdapterExtras;

/* … */

    AdRequest adRequest = new AdRequest();

    /* Set parameters common to all networks in 'adRequest' here. */

    // Millennial Media extra parameters.
    MillennialAdapterExtras millennialExtras = new MillennialAdapterExtras();
    millennialExtras.setIncomeInUsDollars(65000);
    adRequest.setNetworkExtras(millennialExtras);
  
    // InMobi extra parameters.
    InMobiAdapterExtras inMobiExtras = new InMobiAdapterExtras();
    inMobiExtras.setIncome(65000);
    adRequest.setNetworkExtras(inMobiExtras);

    /* Similarly set extra parameters for other networks. */

    // Finally, request the ad.
    adView.loadAd(adRequest);

Back to top

6. (optional) Set up an ad listener

To be notified of ad lifecycle events like impressions, you can implement a com.google.ads.AdListener. When using mediation, this listener will automatically notify you about events from all the networks you're mediating. For example, impressions from any ad network will be reported through thecom.google.ads.AdListener method onReceiveAd.

7. (optional) Implement custom events

Custom Events are a way to serve ads from your own ad server, from an ad network that is not featured in AdMob Mediation, or to invoke any other code of your choice.

To create a Custom Event, define a class that implements CustomEventBanner.

A Custom Event must report back to CustomEventBannerListener when it successfully receives an ad or when it fails to receive an ad. To do this, call the appropriate listener method (as shown below). Failing to do this will stop the mediation waterfall from running correctly.

Preferably, your Custom Event should also report clicks and the outcome of the click action (presenting a full-screen modal or leaving the app) by notifying theCustomEventBannerListener. This will allow click stats to be counted in your reporting and will allow any event listeners you've set up to work properly.

We instantiate your CustomEventBanner and set the CustomEventBannerListener for you at runtime—there's no need to instantiate these classes yourself.

Here is an example Custom Event:

public class CustomAd implements CustomEventBanner {
  @Override
  public void requestBannerAd(final CustomEventBannerListener listener,
                              final Activity activity,
                              String label,
                              String serverParameter,
                              AdSize adSize,
                              MediationAdRequest request,
                              Object customEventExtra) {
    ImageView imageView = new ImageView(activity);
    imageView.setImageResource(R.drawable.floodit_ad);
    imageView.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        try {
          listener.onClick();
          listener.onPresentScreen();
          listener.onLeaveApplication();
          Intent intent = new Intent(Intent.ACTION_VIEW,
                                     Uri.parse("market://details?id=com.labpixies.flood"));
          activity.startActivity(intent);
        } catch (Throwable t) {
          // Something went wrong, oh well.
        }
      }
    });
    listener.onReceivedAd(imageView);
/* This custom event will always succeed, so we haven't called the onFailedToReceiveAd method */
  }

  @Override
  public void destroy() {
    // Clean up custom event variables.
  }
}

Refer to the CustomEventBanner and CustomEventBannerListener Javadocs for further details.

Your Custom Event can call methods of the ad request to get access to request parameters like age or gender. See the MediationAdRequest Javadocs for further details on this.

To create an interstitial Custom Event that takes over the entire screen, instead of a Custom Event that lives inside a banner view, useCustomEventInterstitial instead of CustomEventBanner (see the CustomEventInterstitial and CustomEventInterstitialListenerJavadocs for details).

Mediation Networks

See the mediation guide for instructions on setting up ad network mediation. If you run into technical issues while integrating these SDKs, please post to our forum. To submit feedback, please use this link.

Ad Network Documentation Compatible SDK Adapter Customer Support
Adfonic
Global Mobile Advertising Network
Included in Adfonic's SDK. Email support
AdMob
Providing developers tools to promote and monetize mobile apps
Partner page Included in AdMob's SDK. Email support
BrightRoll
BrightRoll delivers mobile video demand from advertising partners
Partner page Download page Included in BrightRoll's SDK. Email support
Domob

Partner page Download Android Download Android Email support
Drawbridge
Bridging audiences across devices
Partner page Included in Drawbridge's SDK. Email support
Flurry
Flurry's AppCircle uses the world's largest data set on app usage
Partner page Download page (login required) Email support
HUNT Mobile Ads
Mobile ad-network targeted to the Spanish & Portuguese-speaking markets
Download Email support
iAd
Connect with iPhone and iPod touch users via Apple's iAd network
Partner page Included as part of iOS. Download Form
i-mobile for SP
Mobile Advertising Network in Japan
Download page (login required) Download page (login required) Form
InMobi
Independent mobile ad network
Form
Jumptap
Provider of targeted mobile advertising
Email support
LifeStreet Media
The leader in in-app advertising
Partner page Download page (login required) Dowload page (login required) Email support
LG U+AD
One Stop Marketing Solution
Partner page Included in LG's SDK. Email support
MdotM
Advertising in a post-pc era
Partner page Email support
Medialets
Rich media platforms enabling high-value mobile and tablet advertising
Partner page Download SDK Included in the Medialets SDK. Email support
Millennial Media
Independent mobile advertising and data platform powering the app economy
Form
MobFox
Premium and performance network focused on Europe and U.S.
Partner page Included in MobFox's SDK. Email support
Mojiva
Breathe life into your mobile strategy
Partner page Download iOS Download Email support
Nend
Mobile Advertising Network in Japan
Included in Nend's SDK.
Pontiflex
Use AppLeads to serve in-app local and national mobile ads
Partner page Download Android Adapter for Android Email support
TapIt!
Leverages mobile advertising solutions and technology to produce brand results
Included in TapIt's SDK. Email support
Tremor Video
Bring the certainty of science to the art of brand marketing
Partner page Email support
Vserv.mobi
We are a Global Ad network with a strong presence in emerging markets
Download Android Adapter for Android Email support

Google disclaims all liability for the vendor information provided on this site, and makes no endorsement of or representation or warranty regarding the vendors, products or services featured on this site. Should you decide to use the products or services of a vendor featured on this site, you will be solely responsible for engaging the vendor, and Google will have no liability for any products or services provided to you by that vendor. Google reserves the right to remove any vendor featured on this site at any time and for any reason.

Additional Controls

  1. Child-directed setting
  2. Requesting test ads
  3. Specifying ad colors
  4. [iOS] Requesting an ad in applicationWillEnterForeground:
  5. [iOS] Releasing your GADBannerView
  6. [iOS] Linking to the correct libGoogleAdMobAds.a binary

Child-directed setting

We have added a new setting to the AdMob SDK called "tag for child directed treatment" for purposes of the Children's Online Privacy Protection Act (COPPA).

As an app developer, you can use this setting to indicate whether you want Google to treat your content as child-directed when you make an ad request. If you indicate that you want Google to treat your content as child-directed via this SDK method, we will take steps to disable IBA and remarketing ads on that ad request. The setting can be used with all recent (Android: 4.1.0+; iOS: 4.0.2+) SDK versions, via "Extras".

  • If you set tag_for_child_directed_treatment to 1, you will indicate that your content should be treated as child-directed for purposes of COPPA.
  • If you set tag_for_child_directed_treatment to 0, you will indicate that your content should not be treated as child-directed for purposes of COPPA.
  • If you do not set tag_for_child_directed_treatment, ad requests will include no indication of how you would like your content treated with respect to COPPA.

By setting this tag, you certify that this notification is accurate and you are authorized to act on behalf of the owner of the app. You understand that abuse of this setting may result in termination of your Google account.

Note: It may take some time for this designation to take effect in applicable Google services.

Code Example

iOSAndroid
AdRequest adRequest = new AdRequest();

AdMobAdapterExtras extras = new AdMobAdapterExtras()
    .addExtra("tag_for_child_directed_treatment", 1);

adRequest.setNetworkExtras(extras);

Requesting test ads

Requesting test ads is recommended when testing your application so you do not request invalid impressions. In addition, you can always count on a test ad being available.

Remember to turn the testing flag off before deploying your app if you want to receive real ads.
iOSAndroid

You can requests test ads by specifying AdRequest.addTestDevice:

AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);         // Emulator
adRequest.addTestDevice("TEST_DEVICE_ID");                // Test Android Device

You can find your Device ID in the logcat output by requesting an ad when debugging on your device.

Alternatively, you can enable test mode via XML with the testDevices attribute in your com.google.ads.AdView element:

ads:testDevices = "TEST_EMULATOR, TEST_DEVICE_ID"

Specifying ad colors

You can control the coloration of text ads by specifying AdRequest.extras or GADRequest.additionalParameters. With these parameters, you can set the background, gradient, border, link, text, and URL colors of the ads you display.

Key Example Value Description
color_bg AAAAFF Background color
color_bg_top FFFFFF Gradient background color at top
color_border FFFFFF Border color
color_link 000080 Link text color
color_text 808080 Text color
color_url 008000 URL color
iOSAndroid
AdRequest adRequest = new AdRequest();

AdMobAdapterExtras extras = new AdMobAdapterExtras()
    .addExtra("color_bg", "AAAAFF")
    .addExtra("color_bg_top", "FFFFFF")
    .addExtra("color_border", "FFFFFF")
    .addExtra("color_link", "000080")
    .addExtra("color_text", "808080")
    .addExtra("color_url", "008000");

adRequest.setNetworkExtras(extras);

[iOS] Requesting an ad in applicationWillEnterForeground:

Do not request an ad in applicationWillEnterForeground:, as the request will be ignored. Place the request in applicationDidBecomeActive: instead.

[iOS] Releasing your GADBannerView

Be careful when releasing your GADBannerView inside one of its delegate's callbacks. If you do decide to do this, use autorelease in place of release to avoid deallocating the GADBannerView while it is finishing up.

[iOS] Linking to the correct libGoogleAdMobAds.a binary

When upgrading to a new version of the AdMob SDK, make sure to link your project against the right binary file. Be sure to check your Build Properties > Library Search Paths to verify this. If the older binary appears before the new one in the search path, your project will inadvertently be built using the older file.

Reporting

You can now run reports for your new AdMob account using the AdSense Management API.

Warning: Legacy AdMob reporting data is not available via the AdSense Management API.

Concepts

Here are some important concepts as they apply to AdMob:

Ad Client:

An ad client specifies a relationship between an account and a product.

You’ll have an ad client ID for your new AdMob account, which will be of the format ca-app-pub-xxxxxxxxxxxxxxxx (you can retrieve your ad clients by using the adclients.list call in the AdSense Management API). This is the ad client ID you should be using for all your AdMob reporting needs.

Ad Unit:

An ad unit specifies an individual placeholder for ads.

You can find your ad unit ID by going to Monetize -> All apps -> [app in question] in your AdMob page. Look for the ad unit you want to report on and find the ad unit ID. It should be in the form ca-app-pub-xxxxxxxxxxxxxxxx/nnnnnnnnnn, but you’ll need to change it to ca-app-pub-xxxxxxxxxxxxxxxx:nnnnnnnnnn to use in the AdSense Management API.

You can also retrieve your ad units by using the adunits.list call in the API.

There are plenty of samples you can check out in the AdSense Management API documentation. You’ll also find a full set of dimensions and metrics there (not all of which will necessarily be relevant for AdMob), as well as the full API reference.

Tips

If you only want to see your AdMob earnings, make sure you set a filter with your AdMob account ID:

filter: "AD_CLIENT_ID==ca-app-pub-xxxxxxxxxxxxxxxx"

Similarly, if you want to see your earnings for a single ad unit, you can set a filter with your ad unit ID:

filter: "AD_UNIT_ID==ca-app-pub-xxxxxxxxxxxxxxxx:nnnnnnnnnn"

Google AdMob Ads for Mobile FAQ

General Information

Development



General Information

Why is Google releasing a new SDK?

Google has been working to weave the Google and AdMob networks together into a single app monetization solution combing their respective strengths. The Google AdMob Ads SDK represents the next major step in this evolution, featuring streamlined APIs, instant access to the latest HTML5 ad units, Android tablet formats, and support for iOS 4.3 and Windows Phone 7.

I'm currently using the AdMob SDK, why should I upgrade?

The new SDK provides numerous advantages over the previous AdMob and AdSense for Mobile Applications SDKs and lays the framework as we work towards a single, comprehensive app monetization solution. Key features include access to the latest ad units, tablet formats for Android, iOS 4.3, and Windows Phone 7 support.

I'm currently mediating between AdMob and Google AdSense for Mobile Apps. Will I still be able to do so with this SDK?

The new Google AdMob Ads SDK is not compatible with the previous Google AdSense for Mobile Applications SDK and therefore cannot be combined with it in AdWhirl.

What determines whether I'm served Google or AdMob ads?

The Google AdMob Ads SDK serves AdMob ads. AdMob offers some developers the ability to display AdSense ads when no AdMob inventory is available. As this program expands Google will be sure to notify you if your app becomes eligible for AdSense backfill.

What ads formats does the SDK support?

This SDK supports current AdMob formats and adds Android tablet support.

Development

How do I get a publisher ID?

You can find directions on how to add AdMob to your site or app here. After you have added your site or app to the AdMob network, you can view your publisher ID by clicking the Manage Settings button under your app's name in the Sites & Apps tab.

I think I've implemented everything correctly, so why am I not seeing ads?

While maintaining the highest possible fill rate is one of our top priorities, we may not always have an ad available for every ad request. This can be especially common during development, when ad requests are typically made infrequently from a small number of users and devices. When apps are newly registered on AdMob it may also take some time and several requests before impressions are consistently delivered. Developers generally see more consistent results once they have released their app and ad requests arrive more frequently from a more diverse user base.

Try making your ad requests in test mode to verify your implementation. As test mode operates through the same channels as live ads, successfully returning a test ad should verify your code.

Note: The very first time AdMob sees your publisher ID it may take up to two minutes to receive an ad, and this initial two minute lag will recur every time the app goes unused for 24 hours.

Warning: All new Android, iPad, iPhone, and Windows Phone 7 apps created after October 14, 2011 will require one of the following versions of the  Google AdMob Ads SDK:
  • iOS - 4.0.2+
  • Android - 4.1.0+
  • WP7 - 4.0.1+
If you downloaded an SDK from our  official download site, then you're already set. Otherwise you may have an old version of the AdMob SDK, and your new app may not receive any ad impressions until you update your SDK.
Why do I keep getting "AdFailed - Ad not available" on Windows Phone 7?

Windows Phone 7 is new to the AdMob market, so in the short term you may see some low fill rates until advertisers add this platform to their targeting. Using test mode during development should eliminate inventory as a variable in your SDK integration testing. Please see the discussion of this feature here.

Why has my fill rate or revenue changed?

The AdMob network is a dynamic marketplace where inventory supply and demand is constantly balanced across a large, diverse group of advertisers and publishers. Large campaigns moving through the network, fluctuations in demand for specific inventory subsets, new publishers and new devices may all significantly impact fill rate and earnings.

If you've noticed a substantial change in performance we would encourage you to review any changes you've made to your app code that might affect our ability to serve ads and check that your account's filter settings are as permissive as possible. Restrictive filtering can significantly reduce the volume of available ads, limiting your app's fill rate and revenue.

How do I control my app's ad refresh rate?

AdMob offers the ability to control refresh rate from within your account. Simply log in and click the Manage Settings button under your app's name in the Sites & Apps tab. Your refresh rate is in App Settings.

How do I control what types of ads are shown in my apps?

AdMob provides publishers with significant control over the ads appearing in their apps. Simply log in, click the Manage Settings button under your app's name in theSites & Apps tab and configure your filters under Ad Filters.

Can I restrict my app to only show image ads?

AdMob offers advertisers a variety of different ad formats to help meet their goals and optimize your monetization. Restricting ad display to a specific format is not supported.

Where can I find more help content specific to the AdMob network?

Google Ad Exchange Banners I

This is a Private BETA feature. You will need an Ad Exchange account with the "Applications" product enabled to use this feature.

Google Ad Exchange banner ads use a small portion of the screen to entice users to "click through" to a richer, full-screen experience such as a website or app store page. This guide shows you how to enable your app to serve a banner ad.

iOSAndroid

To display banners in your Android app, simply add a com.google.ads.AdView to your UI.

Adding a com.google.ads.AdView

Android apps are composed of View objects, Java instances the user sees as text areas, buttons, and other controls. AdView is simply another View subclass displaying small HTML5 ads that respond to user touch.

Like any View, an AdView may be created either purely in code or largely in XML.

The five lines of code it takes to add a banner:

  1. Import com.google.ads.*
  2. Declare an AdView instance
  3. Create it, specifying your unit ID as <google_ad_client>/<google_ad_slot>. It should look something like:
    ca-mb-app-pub-1234567890123456/1234567890
  4. Add the view to the UI
  5. Load it with an ad

The easiest place to do all this is in your app's Activity.

import com.google.ads.*;

public class BannerExample extends Activity {
  private AdView adView;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Create the adView
    adView = new AdView(this, AdSize.BANNER, MY_AD_UNIT_ID);

    // Look up your LinearLayout assuming it's been given
    // the attribute android:id="@+id/mainLayout"
    LinearLayout layout = (LinearLayout)findViewById(R.id.mainLayout);

    // Add the adView to it
    layout.addView(adView);

    // Initiate a generic request to load it with an ad
    adView.loadAd(new AdRequest());
  }

  @Override
  public void onDestroy() {
    if (adView != null) {
      adView.destroy();
    }
    super.onDestroy();
  }
}
Warning: Make sure you're in test mode during development to avoid being disabled for clicking your own ads. See the  Additional Controls guide for more details on enabling test ads.

You can download an example project containing this code.

Create your banner in XML

Rather than creating your AdView in Java, it's also possible to set one up entirely in XML. To do so simply:

  • Incorporate the SDK into your app.
  • Define a com.google.ads.AdView in res/layout/main.xml, specifying it should immediately load an ad by using the ads:loadAdOnCreateattribute.
  • Alternately, instead of forcing the AdView to load an ad immediately, look up the AdView as a resource at runtime and tell it to request an ad.

Defining a com.google.ads.AdView

The easiest way to incorporate an ad is to simply define your AdView as you would any other part of your res/layout/main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
  <com.google.ads.AdView android:id="@+id/adView"
                         android:layout_width="wrap_content"
                         android:layout_height="wrap_content"
                         ads:adUnitId="MY_AD_UNIT_ID"
                         ads:adSize="BANNER"
                         ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
                         ads:loadAdOnCreate="true"/>
</LinearLayout>

As usual you must replace MY_AD_UNIT_ID with your Ad Slot ID. You must also add your own device ID in the ads:testDevices attribute to get test ads on your device. Note the inclusion of the ads namespace referenced in specifying adUnitId and adSize. This code will immediately attempt to load an ad as soon as the AdView is created by Android's layout engine.

Lookup and Load

If you have a need to control the AdRequest used to load an ad in your application, you can remove the ads:loadAdOnCreate="true" line from the above code. Instead, you will want to look up the AdView as a resource via findViewById and instruct it to loadAd:

import com.google.ads.*;

public class BannerExample extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    // Look up the AdView as a resource and load a request.
    AdView adView = (AdView)this.findViewById(R.id.adView);
    adView.loadAd(new AdRequest());
  }
}

You can download an example project containing this code here.

The Result

When you now run your app you should see a banner at the top of the screen:

Warning: All new Android apps created after October 14, 2011 will require a  Google AdMob Ads SDK that was released on or after May 11, 2011. This corresponds to version 4.1.0+ for Android. If you downloaded the library from our  official download site, then you're already set. Otherwise you may have an old version of the Google AdMob Ads SDK that was released prior to May 11, 2011, and your new app will not receive any ad impressions until you update your SDK.

Proceed to the next guide to learn more about banner ads.

Google Ad Exchange Banners II

This is a Private BETA feature. You will need an Ad Exchange account with the "Applications" product enabled to use this feature.

In this guide, we show you more ways to control banner ad properties.

iOSAndroid
  1. Banner Sizes
  2. com.google.ads.AdRequest
  3. com.google.ads.AdListener

Banner Sizes

Google Ad Exchange Ads supports three tablet-only banner sizes in addition to the 320x50 shown on phones:

Size (WxH) Description Availability AdSize Constant
320x50 Standard Banner Phones and Tablets BANNER
300x250 IAB Medium Rectangle Tablets IAB_MRECT
468x60 IAB Full-Size Banner Tablets IAB_BANNER
728x90 IAB Leaderboard Tablets IAB_LEADERBOARD

The SDK will request whatever size the requesting AdView was instantiated with. If there isn't enough space on the device's screen to display the ad, nothing will be shown.

com.google.ads.AdRequest

Before being passed to AdView.loadAd an AdRequest may be customized to allow Google to better target ads.

AdRequest.addTestDevice | AdRequest.setTestDevices

You can use these properties to specify a device or Set of devices that will receive test ads. You should utilize this property during development to avoid generating false impressions. To verify that you've integrated the SDK correctly, add your test device, run your application, and click on the displayed test ad.

AdRequest request = new AdRequest();

request.addTestDevice(AdRequest.TEST_EMULATOR);
request.addTestDevice("E83D20734F72FB3108F104ABC0FFC738");    // My T-Mobile G1 test phone

logcat will print the device's MD5-hashed ID for convenience, for example: 
  To get test ads on this device, call adRequest.addTestDevice("E83D20734F72FB3108F104ABC0FFC738");

com.google.ads.AdListener

You may optionally track ad lifecycle events like request failures or "click-through" by implementing com.google.ads.AdListener in an object you pass toAdView.setAdListener.

public interface AdListener {
  public void onReceiveAd(Ad ad);
  public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode error);
  public void onPresentScreen(Ad ad);
  public void onDismissScreen(Ad ad);
  public void onLeaveApplication(Ad ad);
}

This interface may be implemented by your activity or any other object:

import com.google.ads.*;

public class BannerExample extends Activity implements AdListener {
}

and then passed to the Ad:

adView.setAdListener(this);
public void onReceiveAd(Ad ad)
Sent when  AdView.loadAd has succeeded.
public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode error)
Sent when  loadAd has failed, typically because of network failure, an application configuration error, or a lack of ad inventory. You may wish to log these events for debugging:
@Override
public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode errorCode) {
  Log.d(MY_LOG_TAG, "failed to receive ad (" + errorCode + ")");
}
public void onPresentScreen(Ad ad)
Called when an  Activity is created in front of your app, presenting the user with a full-screen ad UI in response to their touching the ad.
public void onDismissScreen(Ad ad)
Called when the full-screen  Activity presented with  onPresentScreen has been dismissed and control is returning to your app.
public void onLeaveApplication(Ad ad)
Called when an Ad touch will launch a new application.

You can download an example project containing a sample AdListener here.

Ad Exchange Mobile App Ad Network Optimization

This is a Private BETA feature. You will need an Ad Exchange account with the "Applications" product enabled to use this feature.

Ad Exchange Mobile App Ad Network Optimization allows large application publishers to exercise more control over shown ads and optimize CPM across multiple demand resources.

With Ad Exchange Mobile App Ad Network Optimization, each ad request invokes an internal auction of bids from these specific sources:

  • Google Demand Sources (AdWords, AdMob, Ad Exchange UI)
  • DSPs that participate in the programmatic RTB auction through a bidder
  • Mobile Ad Networks you select and are supported by Ad Exchange
Prices, bid data, and eCPM estimates are compared dynamically based on ad networks reporting data and a single playlist generated. Google may refine the auction logic over time.

The playlist is then returned to the app's SDK which goes through the playlist sequentially, reaching out to each network until a successful ad response is received.

To get started with Ad Exchange Mobile App Ad Network Optimization, contact your Ad Exchange account representative. Then follow the instructions below to install the necessary SDKs/Adapters on your app.

Installing SDKs and adapters

Select either the iOS or Android tab to see the instructions for the respective platform.

  1. Integrate Ad Exchange mobile ads
  2. Add network adapters and SDKs
  3. Configure ad networks in AndroidManifest.xml

1. Integrate Ad Exchange mobile ads

Follow the Getting Started instructions to incorporate the SDK. Then proceed to set up some banner ads.

2. Add network adapters and SDKs

You're now ready to download and add to your project the adapters and SDKs of all the ad networks you'd like to serve ads from. You can find links to them on the network mediation page.

To add the downloaded network adapters/SDKs in Eclipse, right click on your project and select Properties. Then add all the JAR files to your Java Build Path.

3. Configure ad networks in AndroidManifest.xml

You now need to add entries to your AndroidManifest.xml as required by each ad network you intend to use. Instructions from each network can be found from the ad network mediation page. Follow the parts of these instructions related to modifying your AndroidManifest.xml file.

Note that you only need to modify your manifest, and that there is no need to follow the networks' instructions for creating ad views or setting up listeners. The AdMob Mediation SDK will invoke each ad network's adapters and SDKs as necessary to create ads. Further below you'll see how to set up Mediation listeners that notify you of ad events for all of your networks.

FAQs

Can I specify preferred networks and allocate more impression wins to them?
Yes, your account representative can set preferred networks for you.
How is this different from  AdMob mediation?
Ad Exchange Mobile App Ad Network Optimization is targeted towards larger application publishers, sources more than just mobile ads networks, and employs different mediation logic. Ad Exchange Mobile App Ad Network Optimization considers ad networks reporting data and despondency over time when generating the mediation playlist. It automatically optimizes the yield in finer granularity, down to ad unit level.

Mediation Networks

This is a Private BETA feature. You will need an Ad Exchange account with the "Applications" product enabled to use this feature.

Ad Exchange Mobile App Ad Network Optimization supports ad networks through either their own SDKs or with JavaScript tags.

Networks that support SDKs

Ad Network Documentation Compatible SDK Adapter Customer Support
AdMob
Providing developers tools to promote and monetize mobile apps
Partner page Included in AdMob's SDK. Email support
iAd
Connect with iPhone and iPod touch users via Apple's iAd network
Partner page Included as part of iOS. Download Form
InMobi
Independent mobile ad network
Form
Jumptap
Provider of targeted mobile advertising
Email support
Millennial Media
Independent mobile advertising and data platform powering the app economy
Form
MobFox
Premium and performance network focused on Europe and U.S.
Partner page Included in MobFox's SDK. Email support
Mojiva
Breathe life into your mobile strategy
Partner page Download iOS Download Email support

Networks that support JavaScript tags

JavaScript tags are supported through these adapters:

Ad Network Website Customer Support
4INFO
Reach your mobile audience
Partner page Page
AT&T Interactive
Enabling developers to create powerful mobile apps
Partner page Email support
Barons Media
Ad network target marketing
Partner page Form
InMobi
Independent mobile ad network
Partner page Form
Jumptap
Provider of targeted mobile advertising
Partner page Email support
LeadBolt
Maximize your revenue today
Partner page Email support
Millennial Media
Independent mobile advertising and data platform powering the app economy
Partner page Form
MobFox
Premium and performance network focused on Europe and U.S.
Partner page Email support
Mojiva
Breathe life into your mobile strategy
Partner page Email support
Pulse 360
Boost the performance of your CPC, PPC and CPM
Partner page Email support
PulsePoint
Delivers high impact solutions to deeply engage consumers
Partner page Form
Undertone
Standout brand experiences
Partner page Form
ValueClick: Greystripe
Monetize your mobile websites and applications
Partner page Form
WHERE Ads
Part of the PayPal Media Network
Partner page Form
YOC
Europe's leading mobile technology and media provider
Partner page Form

Google disclaims all liability for the vendor information provided on this site, and makes no endorsement of or representation or warranty regarding the vendors, products or services featured on this site. Should you decide to use the products or services of a vendor featured on this site, you will be solely responsible for engaging the vendor, and Google will have no liability for any products or services provided to you by that vendor. Google reserves the right to remove any vendor featured on this site at any time and for any reason.

https://developers.google.com/mobile-ads-sdk/docs/admob/fundamentals

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值