Cordova-plugin-admob not working


#1

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


#2

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…


#3

Thanks for the reply but I tried adding publisher I’d and position also same result


#4

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


#5

I tested in Android device I didn’t got any its none


#6

What version of plugin and ionic do you use?


#7

ionic version 1.4.5
and admob 2.7.8


#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.


#9

still same output no add or banner displays


#10

Try to remove and add again the plugin and the platform. And check javascript console…


#11

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


#12

Try to add

isTesting: true

to the options.


#13

tried with both true and false


#14

Have you seen this blog post?


#15

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


#16

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.


#17

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


#18

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.


#19

You should be using the “AdMob Plugin Pro”…

If I remember correctly I was also not able to make the “non pro” plugin work…


#20

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.