Yuma 4×4

Media and Communications

AdMob Interstitial Ads – Mobile Ads Garage #4

AdMob Interstitial Ads – Mobile Ads Garage #4

Hey, everybody. I’m Andrew Brogdon, and welcome
back to the Mobile Ads Garage, where the videos are like my
mother’s Christmas cookies, chock full of ginger. Today we are all
about interstitials, which is a word I’m still
not sure how to spell. Fortunately, Gary the graphics
guy has no such problems. Nice work, Gar. All right. We’re going to cover the basics
of how interstitial ads fit into apps, and then we’ll code
up a sample implementation in iOS and Android. Now, most of you are probably
familiar with banner ads. They occupy a little
spot in a viewer activity and stay visible while
the user interacts with the rest of the UI. Interstitials, on
the other hand, appear briefly in
between user interactions and they use all of a
device’s screen space. So instead of this, the user
sees something like this. That’s an interstitial. The user can spend a second
or two considering the ad’s message, and either tap on
the ad to click through, or use the Close button at
the top to return to the app. So that’s the basic idea. Now, one other thing
I want to talk about before we get to
implementation is how requests for
interstitials work. Requests for banners
are synchronous. That means the usual
pattern goes like this. You create an ad view. You call its method
to load an ad. And then when the response
comes from the server, it’s immediately
displayed in the ad view. Interstitials are
a little different. Because they cover
the entire UI, you don’t just want to toss them
on screen whenever they load. Instead, you request
them in advance. And then when the moment’s
right, that’s when you display. So their request
flow looks like this. You construct an
interstitial ad object, call a method to load an ad. Then when you’re
ready, you check to make sure it’s
loaded, and display. All right. With that in mind,
let’s get to some code. All right. So here I am in Xcode
with my app right there. It’s really simple
and I’d just like to show an interstitial
when I hit that button. And here are the steps to do so. First, I need to create
a GADInterstitial object. Then I’ll request an ad for
it, wait for the right moment, check to make sure it’s
loaded, and display. So first I’m going to add an
import statement for the Google Mobile Ads SDK to my
view controller code. There we go. And I’m going to come down
here and add a new property for my GADInterstitial. I forgot to make it a pointer. There we go. Now I need to initialize it,
which I’ll do in viewDidLoad. And this is a long statement,
but once I get this typed out, you’ll see that the initializer
takes an ad unit ID. Ad units are created
at apps.admob.com. And you’ll want a unique one
for each spot in your app where you show interstitials. That way you control things
like mediation and campaigns independently. So there we go. So now my
interstitial’s created, so I need to request an ad. And the first step is to build
a GADRequest object, which I can do by calling the static
request method in GADRequest. And once I’ve done
that, I’m also going to give it
the simulator’s ID to make sure that I get
test ads while I’m testing. It’s very important. You should always,
always use test ads when you’re testing your app. Perfect. All right. Now I just need to call my
GADInterstitials load request method, pass it the
request object I just made, and I’m all set. Cool. So the next step is to
wait until the right moment in the flow of the app
and then try and display. We’re going to talk a
lot more about this step and how to pick that right
moment in our next video. Today though, since I’m
just using a button press, waiting for the event
sort of does that for me. That means it’s on
to the last steps. And I just need to add code
to my didReceiveTap method to check if the interstitial has
loaded, and if so, display it. So you can check to see if your
ad has loaded with the IsReady method. So I’ll use that for
my conditional here. And then to display
the ad, I just call presentFromRoot ViewController,,
which in this case is the current class,
so I can use self. Cool. Let’s make sure everything
builds just fine. There we go. And hit the button. And there’s my test ad. Perfect. All right. So we created a GADInterstitial,
requested an ad, waited for the right time,
checked, and displayed. Job done. So that’s a basic example of how
to get an interstitial working in iOS. Now let’s take a look at
interstitials in Android. As you’ll see, it’s the same
steps in a different language. All right. So here I am in Android Studio. I’ve got my app. It’s got a single button. And I’d like to display
an interstitial ad when somebody taps on it. And here are the steps
to make that happen. First, I’m going to create
an interstitial ad object. Then I’ll request an ad for it,
wait until the right moment, check that it’s
loaded, and display. All right. So in my activity, I’ll just
drop in a new private member to hold my
interstitial ad object. There we go. And then I’ll construct it
inside my onCreate method here. Note that interstitials require
a context in their constructor, but since I’m in Activity,
I can just use this. Cool. And last thing, I just need
to give it an ad unit ID. You can make your own ad
units at apps.admob.com. And it’s always a
good idea to have a unique one for each
place in your app where you show an interstitial
so that you can configure them independently. All right. So creating object’s done and
now I need to request an ad. Just like with banners,
to request an ad, I’ll need an ad request
object, so I’ll make a builder. There we go. And I’m going to enter the
emulator as a test device to make sure that
I get test ads. Remember, always,
always use test ads when testing your stuff. There’s the constant. And the I just called the build
method to get my ad request. All right. Ad request in hand. I just need to call the
interstitial ads loadAd method, and that’ll kick off the load. Cool. All right. So step three is waiting
until the right moment. And we’re going to spend
more time on this step and how to pick that right
moment in our next video, but for this example,
I’m just using a button to keep things
simple, so waiting for the event to fire
kind of does that for me. So that brings me to
the last two steps then, which are checking
that the ad is loaded and displaying. And I’ll handle those right
in my onclick handler. To check if an
interstitial has loaded, you can call the
isLoaded method. So I’ll put that
in my conditional. And then to display, I
just need to call show. All right. Let me run this bad boy
and see what happens. And it’s running. Get a click on here,
and there’s my test ad. Perfect. All right. So here are the
steps once again. I created an interstitial
ad object, requested an ad, waited for the right moment,
checked, and displayed. Job done. So now we’ve got a working
ad in both iOS and Android, but there’s a lot
more to interstitials that we haven’t
had time to cover. Things like how to load a
new interstitial after you’ve finished displaying
the previous one, how to pause and resume
game loops so you can avoid wasting CPU cycles,
and when’s the best time show an ad? We’re going to spend some time
on those in our next episode, so be on the lookout for it. In the meantime, I’ve
got some links for you. You can check out our guides
for interstitials on both OSes. And you can get example
code from our GitHub repos, or by using Android Studio’s
Import a Sample option. You might also like
AdMob’s No Nonsense Guide to App 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 related to anything you’ve just seen,
stop by our support forum. And if you’ve got a question
about this video series, or a tip on something
you’d like us to cover, leave a comment below. And Gary and I will
see you next time. [MUSIC PLAYING]

28 thoughts on “AdMob Interstitial Ads – Mobile Ads Garage #4

  1. When Interstitial Ads come in limits then it's ok but when it appears on every click then we start losing our patience.

  2. How would I go about doing this for a game using SpriteKit?
    I had a crack at making a GADInterstitial at the start of my class but it was unsuccessful.

    This is being done in GameScene.swift and it's all done by code (i'm not using storyboards.)

    Any help is greatly appreciated.

  3. i want to add interstitial ads between pages where i can back press second page and come back to main activity……plz help me …if u want then i can send my code …i can implement interstitial ads on click method but i cant find this on internet or any of ur videos …i have grid image view in my app …when i click small image it will come up full image view…when i back press from full image view to come back small image view, that point i have to set interstitial ads..

  4. 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!!!

  5. hi. can I put the interstitial ads before confirmation exit box when user press back button???, is that possible. cause I saw the admob policy that say don't put interstitial ads when user press back button. pls help me out . thAnks

  6. How can I do this in an SpriteKit game with an SKScene class? I think that would be a good idea for a video. Thanks


  8. Sir, I used your method when interstitial ad is ready, i show them to the user, but now ads click rate are reduced almost from 30 to 3 clicks per day, before i was using onAdload overrided function to show ads, there i got more clicks and revenue, plz give me some advice how can i earn revenue now, as banners are not making good money, after that problem i was earning from native express which was pretty good, but now it is depreciated too.

  9. These videos are amazing. Thanks man. After searching the whole internet, I finally found this. After all, the best of Google, comes from Google😉

  10. I had a code for interstitial but I always had to request ad then load add
    is there anyway to just request add one time and then show add whenever i click button

  11. hello Andrew Brogdon i have this problem google sent me message witch is "Interstitial ads that appear after the user has exited the app" so can you tell me the solution about this problem please i have 3 apps that has the same problem and thenk a lot for reading this

    good by

  12. Hi, great and funny tutorial. I've got a problem with interstitial ads orientation. My app is in landscape, but ads is showing portrait. How to request interstitial ads in landscape only?

  13. I've made an webview app. I added interstitial ad on a regular interval. suppose after 120 seconds. When I close the interstitial Ad it take me back to the home page. Suppose I am browsing ABOUT Page. After close the ad it takes me back to the home page. But I want to stay in ABOUT page.

    is there any solution?

    private InterstitialAd mInterstitialAd;
    protected void onCreate(Bundle savedInstanceState) {
    ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
    scheduler.scheduleAtFixedRate(new Runnable() {
    public void run() {
    Log.i("Sample", "CV");
    runOnUiThread(new Runnable() {
    public void run() {
    if (mInterstitialAd.isLoaded()) {
    } else {
    Log.d("TAG", " Interstitial not loaded");
    }, 20, 40, TimeUnit.SECONDS);
    public void prepareAd() {

  14. why all people around the world have massive adrequest but very low impressions ??? why you don't want to fix this issue ,????

  15. Sir anyone can help out me my ads are not showing on android plateform

    ads showing on ios plateform and also test ads are showing on android but live ads are not showing on android plate form why plzz help out me


Leave comment

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