Using Admob With IonicFramework

Having your mobile application generate some kind of revenue is usually critical.  Not many people want to spend endless hours slaving over an app without some kind of profit.  Luckily, using IonicFramework with Apache Cordova device APIs in addition to a nifty and easy to use Admob plugin, you can take full advantage of Google Admob in your cross platform application.

To use Admob with IonicFramework we will be using the floatinghotpot Cordova plugin.

If you’re using Ionic 2, you should visit the revised tutorial I wrote to accommodate the Angular 2 differences.  Otherwise, continue for Ionic Framework 1 and AngularJS.

In your IonicFramework project, make sure that you have already added the Android and iOS platforms.  Run the following commands if you haven’t:

Remember, if you are planning to develop for iOS, you must be using a Mac with Xcode installed.

The next step is to add the floatinghotpot plugin into your project.  Taken directly from the plugin’s README, run the following commands from the command line while in your project’s directory.

Now we are going to deviate from the plugin’s README since we are using AngularJS rather than just Cordova and JavaScript.  To keep things simple, we are going to have the banner ad show up on every screen at the bottom.  If you wanted to be fancy you could expand upon this tutorial however you please.

The device.platform call is one of the Cordova API calls.  If the platform is Android, the plugin will use the Android key that you provided, otherwise it will use the iOS key.  Please note that no ads are going to show up in your web browser since this plugin is for Android, iOS, and Windows Phone only.

Here is an example of what this advertisement looks like on Android:

Admate With Ads

You might be concerned about what happens to the content in your application.  The good news is, by default it will not display on top of your content.  The plugin will push all content above the ad, even if you’re using a footer.  In the example image I provided you’ll notice that I am using a footer in addition to the advertisement and it works fine.

A video version of this article can be seen below.

Nic Raboy

Nic Raboy is an advocate of modern web and mobile development technologies. He has experience in Java, JavaScript, Golang and a variety of frameworks such as Angular, NativeScript, and Apache Cordova. Nic writes about his development experiences related to making web and mobile development easier to understand.

  • Hi Nic,

    Thanks for your post, it was really helpful. I’ve tried it and it kind of works for me, but not perfectly (I’m only testing on Android)

    When I first open the application, everything runs correctly (I’ve checked the logs), but the banner does not show. If I hit the “home” button and then use the “recent apps” button and go back to my application, I can see the banner perfectly.

    I’ve spent quite a bit of time on this, but I can’t understand why it’s happening. Could it be because the first time the app is run, the home page of my app is rendered (ie, the controller runs) before createBannerView() finishes?

    Thanks!

    • Hi Inaki,

      Are you using a custom Android ROM by chance? I’ve only tested on manufacturer shipped Android.

      Anything that is in your .ready() function should run before your controller runs. Can you confirm you are initializing the ads in the .run() area of your AngularJS module?

      The last thing to check is what version of the plugin you’re using. I am not the developer, but I know the developer frequently makes changes. When looking at this commit history, can you please tell me which version you’re using, or at least the date you added the plugin? I can then test to make sure the plugin is not broken.

      I’m happy to help you get this working 🙂

      Cheers,

  • Hi Nic,

    Thanks for the info, really useful! It brought me to the github page for floatinghotpot. Thought you might want to know that requestAd() command you recommend using is being deprecated.

    requestAd(options, success, fail); // optional, will be absolete (sic)

    Instead, looks like you’re supposed to use:

  • Raymond

    Update:

    cordova plugin add https://github.com/MobileChromeApps/google-play-services.git

    This line is not needed. It will cause conflict. The cordova CLI will handle dependency by itself.

    • Thanks for the advice Raymond! I’ve fixed this in the tutorial.

  • kumar

    Am very new to this, quick question..is there a non CLI way of doing this? I am using phonegap build.

    • Hi Kumar,

      If you look at the official floatinghotpot documentation, there are instructions for manual installation.

      However, since Phonegap is built on Apache Cordova, you should have full CLI access.

    • Ted

      Hi Kumar,

      You can’t use phonegap build with the Admob plugin since it uses a native library which is not allowed by phonegap build. The only option I’m aware of that works with PGB is mobfox’s javascript api. You can find more about it here: http://www.mobfox.com/integrate-native-ads-mobile-website/

      I had some problems with their service not returning ads so in the end I gave up on using mobfox and PGB and built everything locally with Admob and the CLI.

      You might also want to check out Intel XDK framework which provides a similar service to PGB but allows you to add third party phonegap plugins that contain binary code.

  • Ted

    Hi Nic,

    What version of IOS are you using? I’m having issues with IOS 7.0 (using the device and emulator) where the banner covers my ionic navigation tabs. I’ve tested with IOS 7.1 and 8.0 and everything works like you’ve described above so the problem seems specific to 7.0. Any ideas on what could be causing this?

    • I am using iOS 8, but I can confirm it worked in 7.1 as well. I want to say it worked in 7.0.x, but I honestly don’t remember. The newer version of the floatinghotpot API has an option for overlay I believe. What Ionic beta version are you using?

      • Ted

        I’m using 1.0.0-beta.13 “lanthanum-leopard” and the newer version of the plugin. I set the overlap option to false (whichalso happens to be the default) but it doesn’t seem to work in ios 7. If I can’t resolve this quickly I’m thinking of just supporting 7.1 and above.

        • I think most Apple users keep their software up to date. The iPhone 4 supports 7.1 as well. I can’t speak for you, but I think it would be safe to drop support for anything below 7.1

  • tons

    i got full screen black after adding the codes

    • Hi,

      Can you tell me what the logs say? You can run the following in Android to accomplish this:

      Most of the time, a black screen means there is an error or typo in your code. Happens to everyone.

      Regards,

      • TONS

        here is my log

        11-12 10:58:18.071: I/CordovaLog(1420): Changing log level to DEBUG(3)
        11-12 10:58:18.071: D/CordovaActivity(1420): CordovaActivity.init()
        11-12 10:58:18.321: V/WebViewChromium(1420): Binding Chromium to the background looper Looper (main, tid 1) {b3d32e08}
        11-12 10:58:18.351: I/chromium(1420): [INFO:library_loader_hooks.cc(112)] Chromium logging enabled: level = 0, default verbosity = 0
        11-12 10:58:18.401: I/BrowserProcessMain(1420): Initializing chromium process, renderers=0
        11-12 10:58:20.341: W/chromium(1420): [WARNING:proxy_service.cc(888)] PAC support disabled because there is no system implementation
        11-12 10:58:20.521: E/chromium(1420): [ERROR:gl_surface_egl.cc(153)] No suitable EGL configs found.
        11-12 10:58:20.521: E/chromium(1420): [ERROR:gl_surface_egl.cc(620)] GLSurfaceEGL::InitializeOneOff failed.
        11-12 10:58:20.531: E/chromium(1420): [ERROR:gl_surface_egl.cc(153)] No suitable EGL configs found.
        11-12 10:58:20.531: E/chromium(1420): [ERROR:gl_surface_egl.cc(620)] GLSurfaceEGL::InitializeOneOff failed.
        11-12 10:58:20.531: E/chromium(1420): [ERROR:gpu_info_collector.cc(86)] gfx::GLSurface::InitializeOneOff() failed
        11-12 10:58:22.961: D/dalvikvm(1420): GC_FOR_ALLOC freed 93K, 7% free 2899K/3108K, paused 371ms, total 395ms
        11-12 10:58:22.971: I/dalvikvm-heap(1420): Grow heap (frag case) to 3.545MB for 635812-byte allocation
        11-12 10:58:23.601: D/dalvikvm(1420): GC_FOR_ALLOC freed 1K, 6% free 3518K/3732K, paused 592ms, total 592ms
        11-12 10:58:24.301: D/CordovaWebView(1420): CordovaWebView is running on device made by: unknown
        11-12 10:58:25.981: D/CordovaActivity(1420): CordovaActivity.createViews()
        11-12 10:58:26.061: D/CordovaWebView(1420): >>> loadUrl(file:///android_asset/www/index.html)
        11-12 10:58:26.061: D/PluginManager(1420): init()
        11-12 10:58:26.131: D/CordovaWebView(1420): >>> loadUrlNow()
        11-12 10:58:26.631: D/CordovaActivity(1420): Resuming the App
        11-12 10:58:28.101: I/Choreographer(1420): Skipped 31 frames! The application may be doing too much work on its main thread.
        11-12 10:58:28.161: D/SoftKeyboardDetect(1420): Ignore this event
        11-12 10:58:28.771: I/Choreographer(1420): Skipped 172 frames! The application may be doing too much work on its main thread.
        11-12 10:58:28.821: D/gralloc_goldfish(1420): Emulator without GPU emulation detected.
        11-12 10:58:29.001: D/SoftKeyboardDetect(1420): Ignore this event
        11-12 10:58:29.371: D/CordovaWebViewClient(1420): onPageStarted(file:///android_asset/www/index.html)
        11-12 10:58:29.371: D/CordovaActivity(1420): onMessage(onPageStarted,file:///android_asset/www/index.html)
        11-12 10:58:43.591: D/JsMessageQueue(1420): Set native->JS mode to OnlineEventsBridgeMode
        11-12 10:58:44.121: D/CordovaLog(1420): file:///android_asset/www/js/app.js: Line 55 : Uncaught SyntaxError: Unexpected token .
        11-12 10:58:44.151: I/chromium(1420): [INFO:CONSOLE(55)] “Uncaught SyntaxError: Unexpected token .”, source: file:///android_asset/www/js/app.js (55)
        11-12 10:58:45.791: D/CordovaActivity(1420): onMessage(spinner,stop)
        11-12 10:58:46.151: E/CordovaWebView(1420): CordovaWebView: TIMEOUT ERROR!
        11-12 10:58:46.611: I/Choreographer(1420): Skipped 33 frames! The application may be doing too much work on its main thread.
        11-12 10:58:48.601: D/CordovaLog(1420): file:///android_asset/www/cordova.js: Line 1169 : deviceready has not fired after 5 seconds.
        11-12 10:58:48.601: I/chromium(1420): [INFO:CONSOLE(1169)] “deviceready has not fired after 5 seconds.”, source: file:///android_asset/www/cordova.js (1169)
        11-12 10:58:48.641: D/CordovaLog(1420): file:///android_asset/www/cordova.js: Line 1162 : Channel not fired: onDOMContentLoaded
        11-12 10:58:48.641: I/chromium(1420): [INFO:CONSOLE(1162)] “Channel not fired: onDOMContentLoaded”, source: file:///android_asset/www/cordova.js (1162)

        • Hi,

          Thanks for the logs!

          See the following lines:

          You have a syntax error on line 55 in your app.js file. Fixing this may get your app working.

          Let me know how it goes.

          Regards,

    • Hi,

      I had to flag your last comment for two reasons:

      1. You included your private publisher ids
      2. I asked for your logs. If the logs are not helpful then we can discuss code, but to save me from wasting a lot of time from debugging your code, we cannot start with the code.

      I hope this makes sense to you.

      Please run adb logcat as it will probably immediately tell us where the problem is.

      Documentation can be found here if you’re unfamiliar with it:

      http://developer.android.com/tools/help/logcat.html

      Regards,

  • TONS

    I posted my logs above please check, thanks for the help in advance

  • I have successfully integrated your plugin for Android, however I can’t seem to build the app for iOs.
    The error I get is:

    clang: error: no such file or directory: ‘[path to my WD]/platforms/ios/fietsAspp/Plugins/com.rjfun.cordova.plugin.admob/CDVAdMob.m’

    Now, when I inspect the plugin the file CDVAdMob.m is actually located in src/ios/CDVAdMob.m.
    According to the plugin.xml the file is located at src/ios/CDVAdMob.m. Which should be correct.
    However, I do not see the entire plugin dir in /platform/ios/[myapp]/Plugins… I guess it didn’t move on install?

    Any ideas on how to fix this?

    • Hi Christian,

      You might try removing the plugin and iOS platform, then trying again.

      Every once in a while plugins and platforms get messed up and need to be re-added.

      Let me know if this does the trick.

      Regards,

  • Ayman

    Hi Nic,
    I followed your guide but its not working, and after some search I found out that the plugin has been updated, so Is your guide is invalid now and that’s my problem?
    Thanks and good job 🙂

    • Hi Ayman,

      What do the logs say? I am aware there are two versions of the Admob plugin, but this guide is for the basic version, not the pro.

      If you can tell me the error logs, I can help you determine why it isn’t working.

      Regards,

      • Ayman

        Thanks for quick reply, here’s my log:

        • Hi Ayman,

          I looked at the logs you provided and there are no errors indicating a problem with Admob.

          Can you please put your code on GitHub and link me? I will take a look.

          Regards,

          • Ayman Mostafa

            Hi Nic,
            First I want to thank you for your time and the quick reply, but befor posting the code and waste your time, I have to menthion that, my AdMob account is new (Created yesterday) and my application is not on Play Store,, So does any of these would be the problem,,, If not tell me and I will post the code 🙂
            Thanks again

          • Hi @aymanmostafa:disqus,

            I’ve never heard of AdMob taking more than a few hours to initialize. This should not be the issue. AdMob also has no real connection with the Play Store, so this shouldn’t be preventing it from working either.

            Have you tried on a physical device rather than simulator? Some simulators prevent ads from rendering because they don’t want to hurt your impressions.

            Let me know.

            Regards,

          • Ayman Mostafa

            Yes I tried 2 devices (Mobile and Tab) and simulator too 🙂

          • Alright, go ahead and throw your code on GitHub. I’ll take a look and we’ll get to the bottom of this.

            Regards,

          • Ayman Mostafa

            Here is the link https://github.com/ayman88/sideapp

            Good Luck

          • Hi @aymanmostafa:disqus,

            See the attached image. I did the following because your Git repository was missing a few components (not your fault).

            1. Download your repository on GitHub
            2. Create a new Ionic project locally
            3. Add the Android platform to the newly created project
            4. Add the AdMob plugin to the newly created project
            5. Copy all your files from your **www** directory into the freshly created **www** directory
            6. Build for Android
            7. Run the APK

            I had to create a new project because Ionic’s **.gitignore** excluded a bunch of the stock plugins. No big deal.

            There appears to be nothing wrong with your code. Maybe try re-adding the platform and plugin again?

            Regards,

          • Ayman Mostafa

            Did you use my www and my AdMob Key?

          • I used the index.html file and your entire js and templates directories. I also used the key you left in your code.

          • Ayman Mostafa

            Very Wierd bro 😀 I dont know what I supposed to do :D, but I’ll keep trying and update you.
            Thanks again, I really appreciate your help 🙂

          • What country are you in? Maybe you’re in a country that doesn’t allow AdMob?

          • Ayman Mostafa

            Egypt, But I used to see Ads from google on apps that I used on my device wheter ios or android !!1

          • I’m all out of ideas because your code worked fine for me. Maybe you have some kind of configuration problem with your computer software? You might try posting this question in the official Ionic forums.

          • Ayman Mostafa
          • Seer Salomon

            here is a crazy idea… Do you have an adblocker of any kind that might be blocking it?

          • Ayman Mostafa

            @Seer Salomon:disqus NO, and I tried it on 2 diff. devices and the simulator !!!

          • Sorry @aymanmostafa:disqus, but I don’t test other peoples binary files. If your code works for me and your country allows AdMob and you have no ad blocker, the only thing I can think of is a configuration problem affecting your build process. I encourage you to post this question in the forums as I no longer believe this is an issue with the plugin or your code.

          • Ayman Mostafa

            Hi Nic,
            What about the cordova Version? I’m using 3.5, what is urs? I took a look on the plugin.xml I found out :

            =3.0.0″ />

            Is that means that I need cordova 3.0.0 ???!!!!

          • I have been using the exact steps of my guide since before 3.5. I currently use 4.0. Still no problems.

          • Ayman Mostafa

            OK, Thanks Bro for your patient 🙂

  • Ayman Mostafa

    Dear Nic,
    I faced issue while installing the AdMob plugin for Android from ur guide, I know that I am interrupting you a lot, but I’m sorry, I am newbie at Mac Enviroment.
    The Error is:

    Fetching plugin “https://github.com/floatinghotpot/cordova-plugin-admob.git” via git clone
    Installing “com.rjfun.cordova.plugin.admob” for android
    Fetching plugin “com.google.admobsdk” via plugin registry
    Installing “com.google.admobsdk” for android
    Fetching plugin “[email protected]” via plugin registry
    Failed to install ‘com.google.admobsdk’:Error: Expected fetched plugin to have ID “[email protected]” but got “com.google.playservices”.
    at checkID (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/fetch.js:116:19)
    at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/fetch.js:99:24
    at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:798:54)
    at self.promiseDispatch.done (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:827:30)
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:760:13)
    at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:574:44
    at flush (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:419:13)
    Failed to install ‘com.rjfun.cordova.plugin.admob’:Error: Expected fetched plugin to have ID “[email protected]” but got “com.google.playservices”.
    at checkID (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/fetch.js:116:19)
    at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/fetch.js:99:24
    at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:798:54)
    at self.promiseDispatch.done (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:827:30)
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:760:13)
    at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:574:44
    at flush (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:419:13)
    Error: Expected fetched plugin to have ID “[email protected]” but got “com.google.playservices”.
    at checkID (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/fetch.js:116:19)
    at /usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/plugman/fetch.js:99:24
    at _fulfilled (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:798:54)
    at self.promiseDispatch.done (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:827:30)
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:760:13)
    at /usr/local/lib/node_modules/cordova/node_modules/q/q.js:574:44
    at flush (/usr/local/lib/node_modules/cordova/node_modules/q/q.js:108:17)
    at process._tickCallback (node.js:419:13)

    Thanks for your time

    Best Regards

    • This guide worked fine on my brand new Mac. This leads me to believe you have a configuration problem in your Apache Cordova, Ionic Framework, NPM, or Android. See the following:

      I encourage you to reach out in the Ionic Framework forums for help in setting up Ionic on a Mac.

      Regards,

    • Peter

      Hi Ayman, I’m getting similar error, how did you fix this?! Thanks.

      • Ayman Mostafa

        Try to update ur invironment to the latest version

  • David Martín

    Hi Nic,
    I’m using this plugin: https://github.com/appfeel/admob-google-cordova
    I’ve noticed that it supports Angular, which I think that it makes live easier! 🙂
    Specially the events (they are broadcasted) so they and can be listened by any controller.
    Also it is published in cordova plugin registry so it’s easier to add with cordova add plugin com.admob.google

    • Does seem like a decent alternative. I have never used it so I can’t put in my two cents, but the more options you have the better.

      Thanks for sharing 🙂

  • jsncrdnl

    Hi, first of all, thank you for this great tutorial, thanks for sharing !

    I’m trying to implement your solution with my ionic app but it doesn’t work…

    AdMob plugin exists, I changed the PublisherID with mine but when it comes to the “createBannerView” function call, I always get stuck at the error callback function with an error message : “Invalid action”…

    I checked in the source code of the cordova admob plugin to see why I got this message and it seems that it’s the function called that is not recognized based on the following code part :

    https://github.com/floatinghotpot/cordova-plugin-admob/blob/484a6be3b7360d0aa555a218d26d31cb61e74780/src/android/AdMob.java#L110

    Do you have an idea why this won’t work ? Or some way to get a more details error message from this plugin ?

    Thanks in advance.

    • Hi,

      I just tried the latest Admob commit with a fresh Ionic project. I wanted to make sure that the plugin developer didn’t introduce breaking changes into a recent commit since I wrote this tutorial several months ago.

      The advertisements displayed fine without error as seen in the screenshot I included to this comment. I copied the code exactly as seen in this blog post. I only switched out the publisher id values.

      Are you in a country where Admob is blocked?

      Regards,

      • jsncrdnl

        Hi ! Thanks for the answer / interest ! ^^

        I’m from Belgium and it’s not blocked because I’m currently using it for a native android application using google play services…

        I ran several test with multiple admob plugin and I still didn’t find a working sample to integrate to my current ionic projet.

        Do you think it could be linked to the fact that I installed many “admob” implementation to my project ?

        I’m also wondering, aren’t there other admob implementation available since you published this post ?

        I saw the ngCordova admob plugin (http://ngcordova.com/docs/plugins/adMob/ ) but implementation is not described yet …

        First of all, I’ll to restart my app from scratch and then I’ll follow you tuto again, to be sure that it’s not linked to something else I’d have installed earlier..

        Many thanks for your support !

      • jsncrdnl

        I ran a new blank ionic projet and added admob with my publisherID using your tutorial and it’s fully working !
        It’s probably linked to a conflict with a plugin I installed or so…
        Thank you again for the great and simple tuto ! ^^

        • Awesome! I’m glad it worked out 🙂

  • Ron B

    Hi Nic, thats for the tutorial.

    I’m having some problems getting ads to work. I can’t rap my brain around why it isn’t working. I have the following plugins installed:

    com.google.playservices 19.0.0 “Google Play Services for Android”
    com.rjfun.cordova.plugin.admob 2.1.7 “AdMob”

    This is my code in the apps.js:

    This results in a black banner area at the bottom of the app, however no ad is ever loaded. This code is currently live, on the admob site I can see a couple hundred session. However my impressions and Request rpm are both at zero for a couple of days now. Anybody have any idea what might be wrong?

    • Your code appears to match what I’ve mentioned in the post and the behavior of what you see seems correct as well.

      What country are you in? Maybe you’re in one where Admob is blocked? Also, what shows up in the logs, if anything?

      Regards,

      • Ron B

        Hi Nic, nothing is showing in the logs, the successCallback is called. So I think a proper request is done. I’m in the Netherlands, so I don’t think i’m blocked.

        • Can you upload your APK somewhere and I’ll download it to check out?

          • Ron B

            Got it fixed, the problem was an incorrect setup in admob. Thanks for your help though!

          • Awesome! I’m glad it worked out 🙂

          • danp11

            Hi Ron, what was incorrect in AdMob setup? I still can’t get it work. Thnks

    • Guest

      i have problem..
      Firstly thanks for the tut..was helpful..

      i am using the “Tabs” template and i have used both of the following plugins
      https://github.com/floatinghotpot/cordova-plugin-admob
      https://github.com/appfeel/admob-google-cordova
      //not using both the plugins the same time or on the same project..i mean i have tired them both

      And the ads show up just fine and my app also load ok.

      BUT when i click on a tab or any other link i get a HUGE lag of around 40 seconds.
      And this happens on any iteration with the app?

      i don’t have any other code except of the ad code.

      What seems to be the issue here?

      I have tried using the sidebar template as well and i get the same problem..

      also i have tried moving the code to a factory and some place else and tried to load it..same thing happens the ads load up fine the app loads up fine but i get this HUGE delay..

      no idea why this is happening??

      have posted the same on the forum here:

      http://forum.ionicframework.com/t/adding-ads-to-ionc-app-makes-app-lag/17039

      • What device platform are you using and what version?

        • sry about posting multiple post didn’t mean to spam you..
          i am using Android 4.1 and i am using it on a device and not a emulator

          • What device are you using and have you tried Crosswalk? The runtime in 4.1 is old and slow.

          • no i havent tried crosswalk..will do it and let you know…but its not an issue of the run time..if i remove the admob code and run the app it runs fine without any lag..as soon as this code is inserted things get laggy..i am using a Lenovo A7-50 with the MediaTek MTK8382M quad core chipset clocked at 1.3GHz and 1gb ram..so the device isn’t at fault here

          • You can have the best specs in the world, but if you’re using ancient software anything is possible. Let me know the results of Crosswalk before we jump to any conclusions.

            Regards,

          • hey nic used cross walk like you suggested and turns out is it is a device specific issue…oddly enough both of my devices running 4.1 and 4.2 had the same problem so i thought problem was somewhere else..
            Ran it on a few other similar devices of friends and found no problem at all

            but its solved now..

            Thanks for reply and keep making such content rich tutorials..thanks

          • Thanks for reporting back!

  • i have problem..
    Firstly thanks for the tut..was helpful..

    i am using the “Tabs” template and i have used both of the following plugins
    https://github.com/floatinghot
    https://github.com/appfeel/adm
    //not using both the plugins the same time or on the same project..i mean i have tired them both

    And the ads show up just fine and my app also load ok.

    BUT when i click on a tab or any other link i get a HUGE lag of around 40 seconds.
    And this happens on any interaction with the app?

    i don’t have any other code except of the ad code.

    What seems to be the issue here?

    I have tried using the sidebar template as well and i get the same problem..

    also
    i have tried moving the code to a factory and some place else and tried
    to load it..same thing happens the ads load up fine the app loads up
    fine but i get this HUGE delay..

    no idea why this is happening??

    have posted the same on the forum here:

    http://forum.ionicframework.co

  • SubjectiveEffect

    I don’t get how this can be working if you haven’t included ‘ngCordova’ in the dependences. I’m using your method and all I get is an error about Admob plugin not being available .

    • ngCordova is not a requirement when using Apache Cordova plugins since it is only an AngularJS wrapper. This is why I’ve chosen not to use it for this particular plugin.

      Did you install the Admob plugin like mentioned in my article? Also, make sure you are not running from a web browser. Plugins do not work in a web browser.

      Regards,

  • Michael Demetriou

    Hello Nic and many thanks for your tutorial.. I was trying to implement this while I had crosswalk added to the project and didn’t work out for me.. However, when I removed crosswalk from the project everything worked just fine! It would be good to know why it was not working with crosswalk!

    • I actually ship my apps vanilla, so I haven’t tried Admob with Crosswalk, but I do find it weird.

      Are there any errors in the logs when you use Crosswalk?

      Regards,

      • Michael Demetriou

        ERROR building one of the platforms: Error: Command failed with exit code 8 You may not have the required environment or OS to build this project. Bare in mind that I have updated cli and all the latest android tools..

        • So it doesn’t fail at run-time, but compile-time instead? That is weird.

          You may want to post in the forums to see if anyone is having issues related to plugins with Crosswalk.

          • Michael Demetriou

            I will! Thanks for your time!

  • danp11

    Hi Nic, i’ve followed all the steps in your tutorial in many apps, even create a new one only for testing and copying your code. I cant see any ad on my apps neither on IOS or Android.

    I’ve just created my AdMob account and I’m living in Brazil. Do you know if it takes some times to deliver? I really don’t know whats is going on. Please help.

    • I think Google says it can take 72 hours. Do you have any error logs?

      Regards,

  • Todd Rimes

    Hi, Nic:

    First of all thank you for this tutorial. I couldn’t get adMob working until I found this.

    Question: How would you recommend restricting adMob to specific views? Some of my views just don’t look right with the ad; in fact, on a YouTube video playback view on Android, it prevents the video from going landscape. Not good. Any advice?

    Thank you,
    ~Todd

    • If you make your admob variable global to your project, you can call (I think) admob.hide() in the particular controller that you wish to not display ads.

      Does that make sense?

      Regards,

      • Todd Rimes

        Sure does. I’ll try it – thank you!

        • No problem. Circle back with your results 🙂

  • hey nic, i did the admob code with ionic app and it works fine when i use the CLI to build the app but using the phonegap build cloud service doesn’t show ads.

    i know that phonegap is an implemantation of “raw” cordova and ionic is based off of cordova, is that the reason for this problem?

    • I don’t use Phonegap Build so I can’t say for sure, but I’ve heard people run into issues when using plugins in their projects that aren’t specifically part of the Apache Cordova channel.

      If the plugin doesn’t exist as part of Phonegaps plugin repository, it won’t know how to set it up.

      I encourage you to build from your local computer and install rather than using a cloud service. It is the best way to develop and test your applications.

      Regards,

      • thanks, but the plugin here is the admob pro plugin by floatinghotpot which is part of the registry. so its kinda strange .
        Is there a multi-platform build service for ionic which can give ios and Windows apps as well?

        • My tutorial is not for the pro version. It is my understanding that there are significant differences between the two versions.

          Again, I don’t use build services. I build only from my local computer. It gives flawless results every time. I encourage you to do the same.

          Regards,

  • dirk789

    Hi, thanks for your tutorial, do you know how I can use this for Windows Phone?

    • The current version of Ionic Framework does not have Windows Phone support.

      Sorry,

      • dirk789

        Thanks for your reply!

  • If anyone want know about installation the interstitial ads on ionic framework please check out my guide:
    https://www.youtube.com/watch?v=KBYV_9q6P-E

  • technotip

    I’ve implemented the exact code as shown in above article ..but still am getting a black blank space at the bottom of my app – but no ads 🙁

    Here is the link to my app http://technotip.com/mobisphere
    [Check the images in the above app link – to see the blank black space at the bottom of the app.]

    • Could be one of three things:

      You have an error in your logs
      You have the wrong ad id or some other Admob configuration issue
      Your country doesn’t allow Google ads

      • technotip

        How to check error logs? In Chrome console I don’t get any error. Google Play isn’t showing me any errors either. Sorry, I don’t know much about this.
        There is no much configuration in admob. I’ve set ad for interstitial ad. Does that work with above code?
        My country allows Google ads, am sure about that.

        • technotip

          Does ‘interstitial ad’ work with above code?

          • My example is for banner ads, but to my knowledge the plugin also supports interstitial ads.

          • technotip

            Checked everything intensively!

            Above code is not working for ‘interstitial ad’. I switched to ‘banner ads’ and everything works fine now.

            But please can you make it work for ‘interstitial ad’ too???

            Am sure, many people are facing problem because they’re trying to implement above code with their ‘interstitial ad’ unit.

          • technotip

            Is there a way to refresh or reload the ad when the user navigates to different views?

            And it would be very helpful if you can implement the code for ‘interstitial ad’ too ..

          • If you refresh the ad every time the view is changed, your impressions are going to be crazy high which will in return give you very poor earnings. You may want to research how earnings are calculated with Admob.

            As for the background, you’ll have to contact the plugin developer because it will probably need to be done via native code.

            Regards,

          • technotip

            Thanks a lot for the info..I had thought more impressions more money!!

            Thanks once again for the tutorial, it saved a lot of my time.

          • No problem!

          • Interstitials is a different topic. I encourage you to read the official plugin documentation and if it doesn’t work out you may want to open an issue ticket with the developer. It should be similar to my example, but definitely not the same.

            Regards,

        • Please see this for finding logs:

          https://www.thepolyglotdeveloper.com/2014/12/debugging-android-source-code-adb/

          Circle back with anything you find.

          Regards,

  • Jess Patton

    So I spent all weekend trying to figure out why my ads were not showing. So hopefully this helps someone else. I run a custom rom on my phone. The custom rom has ad block built in (which I was unaware of until now) This will keep ads from showing but will not throw any erros. I facepalmed so hard when I realized what was going on. Your code worked perfectly thank you!

    • I’m glad you got it working :-). Thanks for sharing this information about custom roms!

  • Vikram

    This is not working, please share any working apk if possible

    • What do your error logs say? What isn’t working?

      I do not give out APK files. The goal is to make the written post and video enough to get the job done.

      Regards,

      • Vikram

        Thanks for your response, it is working now. I removed the ternary operation which was trying select right publisher id.

  • RedhopIT

    Hello,

    This version of cordova plugin stopped working, you have to use cordova-admob-pro version, your post inspired me to create a little blog post about how to use.

    Anyone who run into the same problem, here is how to use the new version http://redwanhilali.com/ionic-admob-integration/

    Regards

  • Paul Leclerc

    Hello,

    Thanks for this tuto, seems great but doesn’t works for me for now 😛

    Well it doesn’t seems to enter in the first if(window.plugins && window.plugins.AdMob) condition. I put a else with console.log and saw the message displaying.
    I have added the plugin, I run it into my Android device on Lolipop.

    Other plugins work fine in my differents controllers.

  • Masthan

    Hello,

    I added “cordova-plugin-admob” it is successfully added. After that, I added admob code in app.js. while building apk it is showing an error. i mentioned below

    “ERROR building one of the platforms: Error: cmd: Command failed with exit code 8

    You may not have the required environment or OS to build this project.”

    Please, Can you tell why i am getting this error while building. Give suggestion for resolving this issue.

    • Is everything configured correctly (Android, Cordova, Ionic)?

      Doesn’t look like a plugin related error. Looks like a system configuration error.

      Regards,

    • I had the same problem. I fixed it by using updated version of admob plugin which is now cordova-plugin-admobpro. To use admobpro you’ll have to first uninstall the old one cordova plugin rm com.rjfun.cordova.plugin.admob and then install admobpro using cordova plugin add cordova-plugin-admobpro.

      Hope this helps.

  • Jae hyun yoo

    Hi, with the admob cordova, is it possible to get specific banner based on location?

    • That is a question to ask Google Admob. I believe you can setup things like that in their dashboard. This won’t be app or plugin related.

      Regards,

  • Thanh TRAN

    Hi
    Thanks for this tutorial.

    Where can I find the Android pushlisher key ?

  • Anvesh P

    Hello,

    I have added Google Admob (Ads) to my App. It is working fine with either at the top or bottom of the screen. Is it possible to show the ads both at top and bottom of the same screen?

    • Thanh TRAN

      Hello did you follow this tutorial to make Admob works ?

      I follow this tutorial but it doesn’t work. I have a lot of error like “/platforms/android/src/com/rjfun/cordova/plugin/AdMob.java:219: error: cannot find symbol”

      • Can you please include your full error logs?

        • Thanh TRAN

          /home/tran_1/tmp/contact/platforms/android/src/com/rjfun/cordova/plugin/AdMob.java:219: error: cannot find symbol

          symbol: method getRootView()

          location: variable webView of type CordovaWebView

          /home/tran_1/tmp/contact/platforms/android/src/com/rjfun/cordova/plugin/AdMob.java:411: error: cannot find symbol

          symbol: method getParent()

          location: variable webView of type CordovaWebView

          Note: Some input files use or override a deprecated API.

          Note: Recompile with -Xlint:deprecation for details.

          2 errors

          FAILED

          FAILURE: Build failed with an exception.

          What went wrong:

          Execution failed for task ‘:compileDebugJava’.

          Compilation failed; see the compiler error output for details.

          Try:

          Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output.

          BUILD FAILED

          Total time: 19.188 secs

          /home/tran_1/tmp/contact/platforms/android/cordova/node_modules/q/q.js:126

          Error code 1 for command: /home/tran_1/tmp/contact/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/tran_1/tmp/contact/platforms/android/build.gradle,-Dorg.gradle.daemon=true

          ERROR building one of the platforms: Error: /home/tran_1/tmp/contact/platforms/android/cordova/build: Command failed with exit code 1

          You may not have the required environment or OS to build this project

          Error: /home/tran_1/tmp/contact/platforms/android/cordova/build: Command failed with exit code 1

          Thanks you, it happens when I build or run

          • Definitely looks like a plugin-level bug. You should open an issue ticket with the developer and paste the exact log you pasted here.

            Sorry,

          • Thanh TRAN

            I found the problem. The problem this is the old version of AdMob, if you use cordova >= 5.0 you have to use AdmobPro.

            I found this : https://github.com/santonocito/angular-admobpro

            Angular admobpro built on top of cordova AdMonPro. It works pretty well but only on emulator, not on my device. Have you any ideas ?

    • I am not sure if that is possible. Even if it is, I highly recommend against it. Having a banner at both top and bottom of the screen will leave very little room for your application for users on smaller devices. Not to mention the app will become slow and unusable.

      Regards,

  • Anvesh P

    Hello Nic,

    I have added Google Admob (Ads) to my App. It is working fine with either at the top or bottom of the screen. Is it possible to show the ads both at top and bottom of the same screen?

  • Scrubles

    Hello there.
    I added the Admob, but I’m having a problem when the keyboard is open, it doesn’t let me scroll down after a certain point, it’s like the rest of the screen is behind the keyboard. Without the admob it works perfectly, it even adjust to the field.

  • someone

    Hellp, i followed the tutorial exactly as stated, but the ads won’t show up , no matter what i do? is the tutorial working ? have there been any changes in the steps since you posted it
    ?

  • himanshu purohit

    Its not working.

    • Your comment is probably the least informative thing I’ve ever read.

      Whats not working? It shows the wrong ads? It doesn’t show ads at all? It only shows ads on iOS, but not Android? The application crashes?

      I’m sure you get the idea that I’m trying to prove. You’ve given me nothing to go off of to try to help you.

      Why don’t you tell me, with detail, your problem and provide me device logs to go with it. Only then can I provide you with decent answers.

      Regards,

      • himanshu purohit

        It doesn’t show ads at all. I did follow your steps but while installing plugin It shows that the plugin is moved to cordova-plugin-admob. So I installed that plugin and follow rest of your instructions but ads are not appearing.

        • Yea so until I see your logs I cannot help you.

          Regards,

          • himanshu purohit

            Thank you, Its working now. I am using AdmobPro plugin and it is working fine.

        • Eduardo hillebrand

          dumb

  • Kopinath Nallhaswami

    Hi Nic , I was trying to implement in android but it is not showing ad at all !!! any help would be appreciated…

    • What do your logs say?

      • Kopinath Nallhaswami

        Nic thanks for getting back…I have solved this issue with himanshu’s help….

    • himanshu purohit

      You should try AdmobPro. It working fine for me.
      https://github.com/floatinghotpot/cordova-admob-pro

      • Kopinath Nallhaswami

        thanks a lot himanshu……its working like a charm…..

        • himanshu purohit

          my pleasure

  • ANSHU KUMAR

    hey Nic, I want to show only some particular ads in my app. That is, only those adds that are paid locally.(eg. in news app) How can i do that?? Please reply asap

  • Oak Krittee

    hi. I create new project (ionic android)
    and add admobpro plugin > cordova plugin add cordova-plugin-admobpro

    and import my project to eclipse.

    i can’t build and run my project. it’s error (google-play-services not includes) **show this picture.

    I don’t khow why? please help me.

    thankyou.

    • This article is not for the pro version of the plugin. I also don’t use Eclipse, so I wouldn’t be of much help in that area.

      My assumption is the plugin didn’t install correctly. Try removing it and trying again.

  • Craig Weiser

    Hi, thanks for the tutorial.

    I have one question. If I wanted to give the user the opportunity to “remove” the ads through an “in app purchase”, how would I disable the ads for those who have paid?

    Thanks

    • Check if the app was purchased and if it wasn’t display the ad? I think it would be better than trying to disable them. Just skip the logic all together if they purchased

      • Craig Weiser

        OK, but what would be the best way to check if the ad was purchased? Localstorage or is there an extra method for this?

        Where would you check for the purchase? Here for example? Or is there a better place?

        if(window.plugins && window.plugins.AdMob && noPurchase()) {


        }

        Thanks

        • Well I don’t know how you’re handling InAppBilling, but yea I guess you can do it that way. In my app I check what the user has purchased every time the application opens in the “module.run”. If the InAppBilling APIs say that ad-removal was purchased I don’t initialize any of the admob logic. Otherwise if the purchase cannot be verified initialize and show the ads.

          Careful with local storage. If you’re relying on local storage, I can easily go in with a 3rd party app and edit the local storage entry to give the illusion that I purchased your pro edition. This is why I do the check against the API every time the app opens. Of course you can use a mix if you want and do it every other time. Really depends on how you plan on doing your logic. Not something I can decide for you.

          Best,

          • Craig Weiser

            Thanks, I have it working with localStorage. I would like to follow your advice and check against the API when the app opens.

            I looked at you posts about in app purchases, but I would like to use one plugin for both android and ios. I will try to get the new plugin from j3k0 to work. Seems a bit different from the one mentioned in the ios post.

            https://github.com/j3k0/cordova-plugin-purchase

            If you have any tips for this plugin that’d be cool.

            Anyways thanks again 🙂

          • I haven’t used the newer j3k0 plugin sorry.

  • Edson Baks

    Hello,

    Thanks for all your tutorials. I’ve learned ionic by reading most of them.
    I just folowed your tutorial but I’m facing the following error “TypeError: Cannot read property ‘AdMob’ of undefined”

    I then tryed with admobpro but same error. i’m testing on android device.
    Have you heard about this error ?
    Thanks

  • giri prasath

    Hello,

    Thanks for your tutorials. i got following error when installing the plugin

    fetching plugin “cordova-plugin-admob” via npm

    Error: Forward-slash in opening tag not followed by >

    line:49

    column:60

    char

    • zaguerinho

      same here? did you solve it?

    • Fede

      Same, any idea?

  • Ranjit p

    I am unable to display Ad at bottom of the screen. I am using option ‘positionAtTop’: false && ‘bannerAtTop’: false . But no use . I am using Ionic framewrok. Can you please helpme out.

    • What do your logs say?

      • Ranjit p

        I am not getting any error …

  • britt dino

    Hi please help. I am using construct 2 to make my game and I am trying to use admob for ads in my android game. But eversince installing admob to it, I can no longer preview the game and it just flashes and goes to a full black screen and stays that way. Whenever I remove admob plugin it works again. What am I doing wrong please respond as soon as possible. The plugin I used is the newest Intel xdk plugin

  • David Bwire

    Thanks for sharing.

  • Craig Weiser

    Hi Nic,

    I am having a problem with interstitial ads. I would like to have an ad shown after level 2, but not at startup.

    Please take a look at my question on stackoverflow.

    http://stackoverflow.com/questions/35350047/how-to-show-an-admob-interstitial-ad-only-after-a-complete-level-with-ionic

    Maybe you have an idea what I am doing wrong.

    Thanks

  • Thomas Vaeth

    I’ve done nothing but start the app. I run cordova plugin add com.rjfun.cordova.plugin.admob and I am getting this:

    Notice: com.rjfun.cordova.plugin.admob has been automatically converted to cordova-plugin-admob and fetched from npm. This is due to our old plugins registry shutting down.
    Fetching plugin “cordova-plugin-admob” via npm
    Error: Forward-slash in opening tag not followed by >
    Line: 49
    Column: 60
    Char:

    I am not sure what to do? I don’t know what line 49 column 60 is even referring to.

  • Gegejosper Ceniza

    Hello Nic,

    Again.. this is not working to me 🙁 I really do not know how to fix it.. did not show any error in my catlog… Is this a problem on ionic versions, cordova versions? I update it all but still not working in android.. please help

  • harish

    Hi Nic,

    i am using cordova plugin add com.rjfun.cordova.plugin.admob with this plugin am able to show ads at the bottom_ center of the screen. As per my requirement i need to show Ad banner in a specific div of the screen. complete intention is to hide that div with Admob banner when user click on a button i need to hide that banner and show the hidden div.

    is it possible to place admob banner a specific div?

    Thanks

    • I would not do it that way for this reason. If you are only hiding the div, the advertisement is still loading and it is still counting as an impression. If your click to impression ration is way off, you’re going to earn less in revenue.

      If your intention is to have a freemium model where ads are hidden if they paid to have them removed, you should do your logic check before loading the ad. This way the ad is never loaded and the impression doesn’t count against you.

      Best,

      • harish

        Thanks Nic for your response. I understood the disadvantage with that.

        For my knowledge i want to learn showing ads in specific div. is that possible at least?
        Even i tried with admob pro plugin also to set the position of the ad banner but i am unable to set it.
        If it is possible can you to explain how to set it.

        Thanks & Regards

        • I don’t think it is possible. Pretty sure Adwords was meant to be top banner, bottom banner, and interstitial only.

          You’d have to consult the docs.

          Best,

  • Nguyen Di

    Hi Nic,
    I got an error when build for android :
    “D:Program FilesnodejsmycodeAdmobDemo2platformsandroidsrccomrjfuncordovapluginAdMob.java:219: error: cannot find symbol
    ((ViewGroup) webView.getRootView()).addView(adViewLayout, params);
    ^
    symbol: method getRootView()
    location: variable webView of type CordovaWebView
    D:Program FilesnodejsmycodeAdmobDemo2platformsandroidsrccomrjfuncordovapluginAdMob.java:411: error: cannot find symbol
    ViewGroup parentView = (ViewGroup) webView.getParent();
    ^
    symbol: method getParent()
    location: variable webView of type CordovaWebView”

    Can you help me

    • I’ve never seen that error before, but since it is a native language error it may be a bug with the plugin itself. You are probably best opening a ticket with the plugin developer.

      Had this been a runtime JavaScript error, I would think differently.

      Best,

  • Bankim Ch. Debnath

    Hi I was trying to install the plugin but getting error.. Can you please look on this and help me out..

    Bankims-MacBook-Pro:myApp bankimdebnath$cordova plugin add com.rjfun.cordova.plugin.admob
    Error: Registry returned 404 for GET on http://registry.npmjs.org/com.rjfun.cordova.plugin.admob
    Bankims-MacBook-Pro:myApp bankimdebnath$

    • Try this instead:

      cordova plugin add https://github.com/floatinghotpot/cordova-plugin-admob

      • Bankim Ch. Debnath

        Thank you for your reply. But interstitial ad is showing only once. Can you please look into this. I did lot of rnd on this but no luck.

        Thanks.

        • What do you mean only showing once? Tell me what your goal is.

          Best,

          • Bankim Ch. Debnath

            See, once i open the app the ad is showing once means, i have written the code for all tabs i have in app but the ad is showing only once. Not for all the time i tap on tab or side menu.

          • What do your logs say?

          • Bankim Ch. Debnath

            The below log is for iOS. After display the interstitial ad once then I am getting the below logs.

            sidemenuApp[1051:85709] Request Error: Will not send request because interstitial object has been used.

            2016-04-12 00:09:36.841 sidemenuApp[1051:84863] AdMob, onAdDismiss, {‘adNetwork’:’AdMob’,’adType’:’interstitial’,’adEvent’:’onAdDismiss’}
            2016-04-12 00:09:38.320 sidemenuApp[1051:84863] showInterstitial
            2016-04-12 00:09:38.320 sidemenuApp[1051:84863] showInterstitial

          • Are you recreating the interstitial before trying to use it again? I believe you have to recreate it every time you wish to use it.

          • Bankim Ch. Debnath

            Yes, I tried it but not working. Can you please share some sample code for this.

          • Maybe as time permits. You can always make tutorial requests here:

            https://www.thepolyglotdeveloper.com/2015/07/what-programming-tutorials-do-you-want-to-see/

            You might also benefit from the updated Ionic 2 post I made:

            https://www.thepolyglotdeveloper.com/2016/02/monetize-google-admob-ionic-2-mobile-app/

            Best,

  • Shashi Khanal

    Hello Nic,
    I did everything as you said in your video (https://www.youtube.com/watch?v=PmUnan_oXmQ) but no ad is shown in my app.
    No error is shown. I checked console log from inspect element in browser.
    What should I do now?
    Please help.
    Regards

    • What do your ADB logs say?

      • Shashi Khanal

        When I try to run in my device from CLI using “ionic run android –device” it shows following error as in the picture but it works well except the admob ad when I build the apk and run in the device.

          • Shashi Khanal

            Thank you so much for the link but I couldn’t build the ionic app and couldn’t see anything in the adb log. Can we see the error log in adb without being able to build the app?

          • If you are getting compile time issues, you may want to open up an issue ticket for the plugin developer. Compile time issues are not related to Ionic Framework.

            Best,

          • Shashi Khanal

            Isn’t this the same plugin you used in your tutorial video?

          • Yes, but maybe the plugin introduced bugs after I made the video. If you are getting compile time errors, it is out of my control to help. Best contact the developer.

          • Shashi Khanal

            Ok. Thank your for your time.
            Regards

  • Muzammil Ahmed

    I had followed each and every step but failed to see ads on my app.
    Logs shows an error which is given below:
    Uncaught TypeError: Cannot read property ‘AdMob’ of undefined

    • What do your full logs say?

      • Muzammil Ahmed

        It doesn’t identify the admob plugin

        • I’ll try again, what do you full logs say?

          • Muzammil Ahmed

            My logs

          • Muzammil Ahmed

            My cordova and cordova android was not updated. Its working fine after upgrading.

          • umer safeer

            how you have update this means which commands you use
            i have also same problem

  • Muzammil Ahmed

    How to create Interstitial Ads?

  • Kaito

    Hi NIC RABOY. Can you please explain how to display the ads on specific page in the app?

    • Let’s start with you explaining what you’ve tried

      • Kaito

        First, I tried to use the code inside the controller that is assigned to the page (state) and it works but when I exit that page the ad still shown.
        I found another explanation (codes) for using admob.
        It uses this code in $ionicPlatform ( for both banner and Interstitial)

        if(window.AdMob) AdMob.createBanner( {
        adId:admobid.banner,
        position:AdMob.AD_POSITION.BOTTOM_CENTER,
        autoShow:true} );

        if(window.AdMob) AdMob.prepareInterstitial({
        adId:admobid.interstitial,
        isTesting:true,
        autoShow:false
        });

        Then in the controller

        it works with Interstitial, but when I tried with banner by using AdMob.showBanner(); it does not work.

        • I know that this is not the same version of Ionic, but you might check out my Ionic 2 tutorial as the plugin is the same:

          https://www.thepolyglotdeveloper.com/2016/02/monetize-google-admob-ionic-2-mobile-app/

          Basically you want to set autoShow to false for your banner and call the showBanner and hideBanner commands when you want to show and hide.

          Let me know if it puts you on the right track. Remember, pay attention to the AdMob functions, not the Angular 2 code.

  • ashraful haque

    TS2304: Cannot find name ‘AdMob’

  • ashraful haque

    TS2304: Cannot find name ‘admobId’

  • Gowtham

    I followed every step. The app did not appear on emulator so I created .apk and ran it on my device but did not show any banner. It shows the following error while emulating.
    error failed to execute shell command “getprop, emu.uuid”

    • What do your full logs say? Bits and pieces don’t really tell the story.

  • Ahmed Galal

    cordova plugin add com.rjfun.cordova.plugin.admob
    get
    Error: Registry returned 404 for GET on https://registry.npmjs.org/com.rjfun.cordova.plugin.admob

  • angela

    Someone asked how to show two BANNERS Top and Lower into in same view or activity?

    • I don’t believe this is possible. Even if it doesn’t violate Google’s terms, I think it would provide a very poor user experience since half your screen would be advertisements.

      • angela

        in native apps if possible and you have seen in ionic possible?