赞
踩
com.google.ads.AdView
to your UI. 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:
com.google.ads.*
AdView
instance 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.
▸ Rather than creating your AdView
in Java, it's also possible to set one up entirely in XML. To do so simply:
com.google.ads.AdView
in res/layout/main.xml
, specifying it should immediately load an ad by using the ads:loadAdOnCreate
attribute.AdView
to load an ad immediately, Look up the AdView
as a resource at runtime and tell it to request an ad. 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.
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.
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.
In this guide, we show you more ways to control banner ad properties.
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.
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.
Before being passed to AdView.loadAd
an AdRequest
may be customized to allow Google to better target ads.
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");
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.
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)
AdView.loadAd
has succeeded.
public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode error)
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)
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)
Activity
presented with
onPresentScreen
has been dismissed and control is returning to your app.
public void onLeaveApplication(Ad ad)
Ad
touch will launch a new application.
You can download an example project containing a sample AdListener here.
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.
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
:
com.google.ads.*
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.
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.
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.
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.
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.
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.
The final mandatory step is to change your AdMob ad placement into a mediation placement by modifying a few parameters.
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.
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);
Load the interstitial exactly as you would load an AdMob interstitial, for example:
interstitial.loadAd(new AdRequest());
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.
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);
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
.
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 CustomEventInterstitialListener
Javadocs for details).
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
| Included in Adfonic's SDK. | Email support | ||
AdMob
| Partner page | Included in AdMob's SDK. | Email support | |
BrightRoll
| Partner page | Download page | Included in BrightRoll's SDK. | Email support |
Domob
| Partner page | Download Android | Download Android | Email support |
Drawbridge
| Partner page | Included in Drawbridge's SDK. | Email support | |
Flurry
| Partner page | Download page (login required) | Email support | |
HUNT Mobile Ads
| Download | Email support | ||
iAd
| Partner page | Included as part of iOS. | Download | Form |
i-mobile for SP
| Download page (login required) | Download page (login required) | Form | |
InMobi
| Form | |||
Jumptap
| Email support | |||
LifeStreet Media
| Partner page | Download page (login required) | Dowload page (login required) | Email support |
LG U+AD
| Partner page | Included in LG's SDK. | Email support | |
MdotM
| Partner page | Email support | ||
Medialets
| Partner page | Download SDK | Included in the Medialets SDK. | Email support |
Millennial Media
| Form | |||
MobFox
| Partner page | Included in MobFox's SDK. | Email support | |
Mojiva
| Partner page | Download iOS | Download | Email support |
Nend
|
| Included in Nend's SDK. | ||
Pontiflex
| Partner page | Download Android | Adapter for Android | Email support |
TapIt!
| Included in TapIt's SDK. | Email support | ||
Tremor Video
| Partner page | Email support | ||
Vserv.mobi
| 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.
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".
tag_for_child_directed_treatment
to 1
, you will indicate that your content should be treated as child-directed for purposes of COPPA.tag_for_child_directed_treatment
to 0
, you will indicate that your content should not be treated as child-directed for purposes of COPPA.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.
AdRequest adRequest = new AdRequest(); AdMobAdapterExtras extras = new AdMobAdapterExtras() .addExtra("tag_for_child_directed_treatment", 1); adRequest.setNetworkExtras(extras);
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. 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"
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 |
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);
Do not request an ad in applicationWillEnterForeground:
, as the request will be ignored. Place the request in applicationDidBecomeActive:
instead.
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.
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.
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.
Here are some important concepts as they apply to AdMob:
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.
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.
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 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.
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.
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.
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.
This SDK supports current AdMob formats and adds Android tablet support.
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.
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: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.
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.
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.
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.
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.
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.
To display banners in your Android app, simply add a com.google.ads.AdView
to your UI.
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:
com.google.ads.*
AdView
instance<google_ad_client>/<google_ad_slot>
. It should look something like:ca-mb-app-pub-1234567890123456/1234567890
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.
▸ Rather than creating your AdView
in Java, it's also possible to set one up entirely in XML. To do so simply:
com.google.ads.AdView
in res/layout/main.xml
, specifying it should immediately load an ad by using the ads:loadAdOnCreate
attribute.AdView
to load an ad immediately, look up the AdView
as a resource at runtime and tell it to request an ad. 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.
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.
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.
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.
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.
Before being passed to AdView.loadAd
an AdRequest
may be customized to allow Google to better target ads.
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");
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)
AdView.loadAd
has succeeded.
public void onFailedToReceiveAd(Ad ad, AdRequest.ErrorCode error)
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)
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)
Activity
presented with
onPresentScreen
has been dismissed and control is returning to your app.
public void onLeaveApplication(Ad ad)
You can download an example project containing a sample AdListener here.
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:
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.
Select either the iOS or Android tab to see the instructions for the respective platform.
AndroidManifest.xml
Follow the Getting Started instructions to incorporate the SDK. Then proceed to set up some banner ads.
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.
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.
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.
Ad Network | Documentation | Compatible SDK | Adapter | Customer Support |
---|---|---|---|---|
AdMob
| Partner page | Included in AdMob's SDK. | Email support | |
iAd
| Partner page | Included as part of iOS. | Download | Form |
InMobi
| Form | |||
Jumptap
| Email support | |||
Millennial Media
| Form | |||
MobFox
| Partner page | Included in MobFox's SDK. | Email support | |
Mojiva
| Partner page | Download iOS | Download | Email support |
JavaScript tags are supported through these adapters:
Ad Network | Website | Customer Support |
---|---|---|
4INFO
| Partner page | Page |
AT&T Interactive
| Partner page | Email support |
Barons Media
| Partner page | Form |
InMobi
| Partner page | Form |
Jumptap
| Partner page | Email support |
LeadBolt
| Partner page | Email support |
Millennial Media
| Partner page | Form |
MobFox
| Partner page | Email support |
Mojiva
| Partner page | Email support |
Pulse 360
| Partner page | Email support |
PulsePoint
| Partner page | Form |
Undertone
| Partner page | Form |
ValueClick: Greystripe
| Partner page | Form |
WHERE Ads
| Partner page | Form |
YOC
| 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.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。