Yuma 4×4

Media and Communications

AdMob Banner Ads – Mobile Ads Garage #2

AdMob Banner Ads – Mobile Ads Garage #2


Hey, everybody. I’m Andrew Brogdon, and welcome
back to the Mobile Ads Garage, where we cover mobile
ads code the way I enjoy cheese
burgers– thoroughly. In our last episode, we covered
how to import the Google Mobile Ads SDK into your projects. Today, with the help of my
partner, Gary the Graphics Guy, I’m going to build on that
by talking about banner ads. To start, let’s imagine
that I’m in an application. [TONE] Perfect. One of the simplest
ways to monetize an app is just by adding a banner. Here we go. Now, there’s a lot you
can do with banners. You can use different sizes. You can put them in
different places. And you can even animate them. But we’ll keep it
simple for now. Let’s start with Android
Studio and a simple banner across the bottom of the screen. So here’s my app
in Android Studio. It’s just a simple
Hello World, and I’m going to add a banner
ad right at the bottom. And here are the steps involved. So first, I’ll place
an AdView in my layout, then I’ll build
a request object, and then I’ll load an ad. So here’s my layout file,
and I’m going to drop in and AdView element. There we go. And you can see Android
Studio pointing out that I need a new namespace
reference, because of the ads attributes, and I’ll
accept that, no problem. There we go. Now, let’s talk real quick
about what’s in here. So I’ve got the AdView
element right there. I’ve got my width and
height set to Wrap Content, which is what you want. I’ve got some positioning
code, and then I have two attributes
that I really want to draw your attention to. Ad size, right
here, tells the SDK what size ad you want
to load– banner, medium rectangle, that sort of thing. And then add unit ID
tells the SDK which ad unit corresponds to this
banner placement in the ad. Ad units are created
at apps.admob.com, and generally you want
a unique ad unit ID for each of the spots in your
app where an AdView appears. That way you can control things
like mediation and refresh rate and so on independently. Now I can go into
my activity code and find a reference to
that AdView object that just dropped in the layout
file by using Find View By ID. There we go. Perfect. All right. So step 1 done. Now I’ll move on to
building a request. So the SDK has a builder
class for ad requests that makes it really
easy to construct them. So I’ll make a new one here
and call its build method. We’re going to into a lot
more detail on ad requests and how they work
in another video. But for right now, just remember
that every time you load an ad, you’ll need a fresh ad
request object to do it. Now, one thing I am going to
do is add a test device ID to this request by
adding a function called Just Before Build and
giving it the emulators ID. This way I can be sure I’ll
get test ads while I’m testing, and that’s important. Always, always use
test ads to test. OK, that’s all we need here
to build my ad request. So what’s left? Just making the actual
call to load an ad. And since I have
my request object, I just need to call
AdView’s Load Add Method, and I’m ready to go. Excellent. All right. Let’s run this bad boy. And there’s my test banner. Excellent. So I placed an AdView, I built
a request, and loaded an ad. Job done. Great. Now that we’ve got Android
down, let’s move on to iOS and, remember, it’s like
making a tarte tatin instead of an apple pie. Same concepts,
different language. Oh. Fine, Gary. It’s like CK Ogden’s
seminal translation of Wittgenstein’s Tractatus. Same concepts,
different language. You don’t know me. Now, on to Xcode. All right. So here we are in Xcode, and
I’ve got my sample app going. And I’d like a banner
across the bottom. So how can I do that? Well, here are the steps
for showing a banner in iOS. If you just got done
watching the Android section, these should seem very familiar. First, I’m going to place a
GADBannerView on my storyboard. Then I’m going to build
a new request object. And then I load an ad. So here’s my storyboard,
and I’m just going to drop a generic view onto it. Let me drag that over. And then I’ll use the Identity
Inspector to change the class to get GADBannerView. There we go. And now I’ll throw some
constraints on my banner. I’d like it to be at the
bottom of the screen, centered. And the size is going
to be 320 by 50, which is our standard banner size. There we go. Add the constraints. Let’s see how that looks. Cool. Now, I need to get a
reference in my code. I’m going to use
Counterparts and just drag it over to
the View Controller and make a property
called BannerView. Excellent. And you can see
Xcode complaining that I’m missing an import. So let me go ahead and add
one in for Google Mobile Ads. The SDK is distributed
as a framework to make that part easy. Now I just need to give
my banner an ad unit. These are made at
apps.admob.com, and generally for every place in your
app that you show an ad, you’ll need a
different ad unit ID so you can control things like
refresh rate and mediation independently. And last thing, I just
need to give the banner a reference to the Root
View Controller, which my sample app is this one. So GADBannerView is placed. Now I need a request object. Requests are represented
by the GAD Request Class in iOS, which has a static
request method to build them. There’s a lot you
can do with requests, which were going to cover in
one of our subsequent videos. For now, just remember that
each time you load an ad, you’ll need to build a fresh
request object to do it. And I’m going to go ahead and
add the simulator to the list of test devices on my request. That way I can be sure I’ll
get a test ad in response to it, which is important. You should always, always use
test ads when you’re testing. They prevent false impressions
and false click-throughs, both of which are bad things. So the only thing left
to do now is load an ad. To do that, I just need to
call the GADBannerView’s Load Request Method and pass
it my ad request object. Excellent. So that’s the last step. Let me run the app,
see what happens. And there’s my test banner. All right. So here are the
steps one more time. To get a banner working, you
just place a GADBannerView, build a request,
and then load an ad. Job done. Banner adds are a great way
to get started monetizing, but there’s a lot
more to talk about. Where’s the best
place to put them? How can you avoid
unintended click-throughs? We’ll cover all that and
more in our next episode. In the meantime, I’ve
got some great resources to link you to like our AdMob
Interstitial Guides for iOS and Android, which have
notes for Java, Objective-C, and Swift. We also have sample
code up on GitHub for both operating systems. So check those out
if you’re interested. You might also like
AdMob’s no-nonsense guide to ad monetization. It’s an overview of
monetization strategies that includes code and
tips from other engineers. As always, if you’ve got a
technical question relating to anything you’ve just seen,
stop by our support forum. And if you’ve got a question
about this video series or an idea for something
you’d like us to cover, leave a comment below, and Gary
and I will see you next time. [MUSIC PLAYING]

60 thoughts on “AdMob Banner Ads – Mobile Ads Garage #2

  1. I really like the presentation where he is within the app. Makes it a bit easier to follow, I think 🙂 Instagram: timhaagdev

  2. I followed every steps on this site https://firebase.google.com/docs/admob/android/quick-start#prerequisites
    But since my computer doesn't support VT, I had to test it with a physical device, and thanks to that the app only closes at start up without giving me any error code.

    The app and everything complied fine, and after 7 hours I've narrowed down to what might have caused the problem.

    I've spent at least 5 hours searching for a solution, where people had a similar problem but they simply mistyped something etc.

    Anyway, this section is what causes the problem for me:

    AdView adView = (AdView)findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);

    As for my .xml

    <com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_alignParentBottom="true"
    ads:adSize="SMART_BANNER"
    ads:adUnitId="@string/banner_ad_unit_id">
    </com.google.android.gms.ads.AdView>

    And build.gradle

    dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.google.firebase:firebase-ads:9.0.1'
    compile 'com.google.android.gms:play-services-ads:9.0.1'
    }

    apply plugin: 'com.google.gms.google-services'

    Would anyone be so kind to help me out? I'm really out of options at this point

  3. Thanks a lot, got it working in my game https://play.google.com/store/apps/details?id=com.OddNames.ArcadeDataEntry

  4. My log says this "Ad finished loading." But I can't see anything ! I've tested it on a Nexus 6P running Android 6.0.1

  5. Hello
    After following all steps now Ads are showing in test device in Debug
    but after publishing in play store Ad is not showing.
    Please suggest what should i do ?

  6. DON'T USE AdMob! After years of quite good numbers this happened few weeks ago: banner's match rate at 40%, fullscreen at 80%, ridiculous RPM and NO SUPPORT AT ALL!!!

  7. Thank you so much! I've been struggling for weeks on this and finally got it!!! One question that may sound noobie. Do I implement that code into my apps APK and generate a new APK to upload to the app store? Or do I leave the code into a new project? I always see people using ads in new projects so that's why I'm asking.

  8. @Andrew Brogdon, I have a question. Consider the following use case:

    1) The user opens the app when he is not connected to the Internet(Hence, the banner ads are not displayed)
    2) The user connects to the Internet (by switching on wifi or mobile data ) when he is using the app.

    What I have noticed is that currently, banner ads are not automatically loaded when the user establishes an Internet connection during usage of the app. I did consider a workaround that included listening for the event of the user connecting to the Internet and then loading the banner ads(if they haven't already been loaded). However, I am not sure if this is the best approach for quite a few reasons.

    One such reason is the following use case:

    1) Steps 1 and 2 mentioned above happen
    2) I implement the connection established listener and load a banner ad upon Internet connectivity establishment.The banner ad has a refresh rate of 50 seconds( which I set when configuring it in Admobs website).
    3) The user now disconnects from the Internet when still using the app. But the banner ad that has been previously loaded is still visible and 20 seconds have ticked off the clock.
    4) The user re connects to the Internet at time=30 seconds.
    Now, should I reload the banner ad because the user just established an Internet connection for the second time(although it has been displayed to the user for just 30 seconds totally out of the configured 50 seconds) or should I leave the current banner ad stay as it is and would it refresh itself after the remaining 20 seconds?

    The above use case is just one reason I could think of.

    Could you please give me the best way to handle this situation?

    P.S : I am asking this question in the context of Android applications. Not iOS. Although, I guess the approach will be more or less the same on both platforms.

  9. After implementing this exactly , I have been facing errors for the past 2 hours
    This is a very incomplete tutorial
    +1 dislike from me

  10. Thank you for such nice tutorial videos.
    Andrew, I have a question,…It is said that we should use a single AdUnit for a single activity, following AdMob Guidelines. So, how many "AdUnits" we can include in a single app?

    Let’s say I have 25 Android Activities in my app, and want to add Banner and Interstitial to 10 activities, so 10 AdUnits, right?So, is their any limit for number of Ad Units in an Android app, which is fine and acceptable by Google AdMob Guidelines?

  11. Thank you for this amazing video!
    I just started with Ads on my android project, and i'm experiencing a problem. When i used your "unitId" and "AppId" every thing works, but when i using my own created banner from my Admob account, I see nothing. So, my question is…
    1. why am i not seeing ads with my own created ads?
    2. Should i deploy my app before adding ads or what?

  12. need quick help from google developer, my banner ads appear on the top of the screen, both of them real device and emulator while testing. how can i fix that?

  13. do we need to call adView.pause() on Activity's onPause() and adView.resume() in Activity's onResume() methods?

  14. I've worked for years with PC's, setting up and installs, but not programming. You were very good in how you presented it all. Although, if a person doesn't understand the basics of where you even went to in order to do what you showed, let alone understanding the coding, how does one do this, when they have the need to integrate ads into a website build. Basically, a pre-beginners hand held walk-through of where to start, where to get the programming software, yada yada yada, and so forth.
    Thanks much, Scott

  15. stop lieing; you confirmed to me that the adsense once disabled still we still be able to use the admob… YOU DISABLE EVEN MY ADMOB, ,,,,,,,,,m,, WHY ? answer please

  16. I'm Getting this error.
    WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.

  17. Actually how much cheapest banner CPM? my new app CPM on play store can go low more than U$0.01, is this normal?

  18. This video instruction is good, but Xcode has since been updated. And using the code from this video in your project now will return errors. What is the new code for the latest Xcode version?

  19. i can't install admob in my project. Whenever i am doing it it is showing a error in my dependencies @ app:compact activity version 28.0.0

  20. WOW! if every google product had clean tutorials like this… coding would be so much more fun! I also have a Question: I cant seem to find the difference in money earned between a regular banner sized Ad and a large banner sized Ad?

  21. I added all the codes and when app call to load ad it not loaded and in admob i able to it as request and imp 0 and match rate is also 0 plz help me

  22. My admob account terminated with balance of +8500$ i didn't receive any email for the reason of termination, i don't know if i'll get my monthly revenue or not, if anyone still working with admob i think it's the best time to switch to another trustable ad network …

  23. while implement of banner it will loaded but not show as per google guild line as well as google git hub sample code.. ? even if not error it just Add was loaded on add listener.. so can you explain why this kind of issues occur while implementing of banner ads. i have put both side add unit on my java as well as XML files.

  24. admob plugin give an error in xcode googlemonbileads.h not found
    why it is give an error i m download the plugin official website ?? i m trying last 3 to 4days

Leave comment

Your email address will not be published. Required fields are marked with *.