Cordova-plugin-admob not working

Hello everyone
I want to add admob to my app and I tried with adding cordova-plugin-admob the plugin gets installed OK and I added the following code for admob in app.js

If(window.plugins.AdMob) {
  var admob = window.AdMob;
  admob.createBannerView({
      'adId': adId,
      'adSize': admob.AD_SIZE.BANNER,
    },
    function() {
      admob.request Ad({
          'isTesting': false
        },
        function() {
          admob.showAd(true);
        },

      )
    }
  )
}

But I am not able to see any adds can anyone help me for this issue

From documentation seems that createBannerView require publisherId and not adId (used instead in createBanner function). Probably you must also specify banner position. Check the documentation and try againā€¦

Thanks for the reply but I tried adding publisher Iā€™d and position also same result

Where do you do your tests? On device? On emulator? You got test banner or none?

I tested in Android device I didnā€™t got any its none

What version of plugin and ionic do you use?

ionic version 1.4.5
and admob 2.7.8

Try with this code:

var banner_opt= {
	adId: adId,
        adSize: AdMob.AD_SIZE.BANNER,
	position:AdMob.AD_POSITION.BOTTOM_CENTER,
	autoShow: true
};
AdMob.createBanner(banner_opt, banner_succ, banner_fail);

And check that adId is your correct admob key.

still same output no add or banner displays

Try to remove and add again the plugin and the platform. And check javascript consoleā€¦

i tried i also tried for a fresh app and installation still its same

Try to add

isTesting: true

to the options.

tried with both true and false

Have you seen this blog post?

1 Like

I tried from given url only, but the plugin used is updated and some parts are changed and i couldnt found any answer for this in the blog post comment section. for ex: instead of windows.plugins.AdMob the new plugin is called as windows.AdMob i am putting my full code below for your reference. i am not getting any errors but also no adds or even white space on ad position

If(window.AdMob) {
  var admob = window.AdMob;
  admob.createBannerView({
      'publisherId': adId,
      'adSize': admob.AD_SIZE.BANNER,
    },
    function() {
      admob.request Ad({
          'isTesting': false
        },
        function() {
          admob.showAd(true);
        },

      )
    }
  )
}

then i also tried

If(window.AdMob) {
      var admob = window.AdMob;
     var banner_opt= {
	adId: adId,
        adSize: AdMob.AD_SIZE.BANNER,
	position:AdMob.AD_POSITION.BOTTOM_CENTER,
	autoShow: true
};
AdMob.createBanner(banner_opt, banner_succ, banner_fail);
    }

i tried with a fresh app and also i tried isTesting true and false both

Hmm, so there could be a few things.

First make sure youā€™re doing this inside of a deviceReady block.
Second, see if you could console.log out window.AdMob. Letā€™s make sure itā€™s something there that you can use.

i am doing inside device ready block but when i use ionic serve and in javascript lof i see undefined for console.log out window.AdMob. as well as console.log out window.pluginsAdMob.

but from device if i alert if (window.AdMob) { alert('text');} its working fine

Is there some error printing on the log when you try to debug on android device? You can see on the logcat or using gapdebug.

You should be using the ā€œAdMob Plugin Proā€ā€¦

If I remember correctly I was also not able to make the ā€œnon proā€ plugin workā€¦

Everything seems to be perfectly alright with the code. I had similar issues when I first used this plugin. But later learnt that we need to use ā€˜Banner Ad Unit IDā€™ in place of adId and not ā€˜Interstitial Ad Unit IDā€™.

Go to AdMob and create banner ad unit and replace the adId with the banner ad unit id. And it must start working.