sunnycupertino / cordova-plugin-admob-simple

Cordova plugin allowing Admob interstitials and banner ads.
MIT License
164 stars 150 forks source link

No add on Android #21

Closed wo-github closed 6 years ago

wo-github commented 7 years ago

If we use this plugin, everything is fine on ios. But the same code doesn`t work on Android. The error event

document.addEventListener('onFailedToReceiveAd', function(data){
        console.log(data)
    });

shows the following:

bubbles:false
cancelBubble:false
cancelable:false
composed:false
currentTarget:null
defaultPrevented:false
error:0
eventPhase:0
isTrusted:false
path:Array(2)
reason:"Internal error"
returnValue:true
srcElement:document
target:document
timeStamp:2790.9700000000003
type:"onFailedToReceiveAd"
__proto__:Event

This happens only with the live Banner. If we call the banner in testmode, everything is fine and the banner is shown.

Our code:

function registerAdEvents() {
    document.addEventListener('onDismissInterstitialAd', function(){
        hideAdMob();
        window.plugins.AdMob.createInterstitialView();      //REMOVE THESE 2 LINES IF USING AUTOSHOW
        window.plugins.AdMob.requestInterstitialAd();     //get the next one ready only after the current one is closed
        //showAdMob();
    });
    document.addEventListener('onFailedToReceiveAd', function(data){
        console.log(data)
    });
}

window.plugins.AdMob.setOptions( {
        publisherId: admobid.banner,
        interstitialAdId: admobid.interstitial,
        adSize: window.plugins.AdMob.AD_SIZE.SMART_BANNER,  //use SMART_BANNER, BANNER, LARGE_BANNER, IAB_MRECT, IAB_BANNER, IAB_LEADERBOARD
        bannerAtTop: false, // set to true, to put banner at top
        overlap: false, // banner will overlap webview
        offsetTopBar: false, // set to true to avoid ios7 status bar overlap
        isTesting: false, // receiving test ad
        autoShow: false // auto show interstitial ad when loaded
    });
    registerAdEvents();
    window.plugins.AdMob.createInterstitialView();
    window.plugins.AdMob.requestInterstitialAd();
    showAdMob();

function showAdMob() {
    $(":mobile-pagecontainer").off("pagecontainershow").on("pagecontainershow", function( event, ui ) {
        var adMobOldHeight = parseInt($(window).height());
        document.addEventListener('onPresentAd', function (e) {
          var difference = adMobOldHeight - parseInt($(window).height());
          $('[data-role="panel"] .ui-panel-inner').css('margin-bottom', difference + 'px');
        });
        document.addEventListener('onDismissAd', function (e) {
          $('[data-role="panel"] .ui-panel-inner').css('margin-bottom', '0px');
        });
        if(typeof window.plugins.AdMob != 'undefined' && window.localStorage.getItem('isLoggedIn') == 0 || window.localStorage.getItem('isLoggedIn') == null) {
            if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){
              //window.plugins.AdMob.createBannerView();
            } else if( window.localStorage.getItem('isLoggedIn') == 0 || window.localStorage.getItem('isLoggedIn') == null) {
              window.plugins.AdMob.createBannerView();
            }
            if($('.ui-page-active').attr('id') != 'StartOverview' && $('.ui-page-active').attr('id') != 'Login') {
                window.plugins.AdMob.showInterstitialAd();
            }
        }
    });
}
sunnycupertino commented 7 years ago

You need to check this before you initialize anything if ( window.plugins && window.plugins.AdMob ) { also where is this bit?

var ad_units = {

            ios : {

                banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx',       //PUT ADMOB ADCODE HERE

                interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx'  //PUT ADMOB ADCODE HERE

            },

            android : {

                banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx',       //PUT ADMOB ADCODE HERE

                interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx'  //PUT ADMOB ADCODE HERE

            }

        };

        var admobid = ( /(android)/i.test(navigator.userAgent) ) ? ad_units.android : ad_units.ios;
wo-github commented 7 years ago

Thats not the problem. The check is there and the variables too. This code works with ios and with the testbanner. And I can insert the ios Add-Ids and it doesnt work on Android.

if ( window.plugins && window.plugins.AdMob ) {
    var ad_units = {
        ios : {
            banner: 'ca-app-pub-xxxxx',
            interstitial: 'ca-app-pub-xxxxx'
        },
        android : {
            banner: 'ca-app-pub-xxxxx',
            interstitial: 'ca-app-pub-xxxxx'
        }
    };
    if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){
        var admobid = ad_units.android;
    } else {
        var admobid = ad_units.ios;
    }
    window.plugins.AdMob.setOptions( {
        publisherId: admobid.banner,
        interstitialAdId: admobid.interstitial,
        adSize: window.plugins.AdMob.AD_SIZE.SMART_BANNER,  //use SMART_BANNER, BANNER, LARGE_BANNER, IAB_MRECT, IAB_BANNER, IAB_LEADERBOARD
        bannerAtTop: false, // set to true, to put banner at top
        overlap: false, // banner will overlap webview
        offsetTopBar: false, // set to true to avoid ios7 status bar overlap
        isTesting: true, // receiving test ad
        autoShow: false // auto show interstitial ad when loaded
    });
    registerAdEvents();
    window.plugins.AdMob.createInterstitialView();
    window.plugins.AdMob.requestInterstitialAd();
    showAdMob();
  }
sunnycupertino commented 7 years ago

When did you register the admob ids? Sometimes they dont serve ads to them for 24 hours. Also is the android app signed? If it's not signed when you test they may also not serve ads.

wo-github commented 7 years ago

The Admob IDs are registered some month ago and the error happens also after build and sign the android app.

JohnScottMcNerney commented 7 years ago

If Ads are like in-app-purchases on Android, you may have to build/sign the app with the same config versions that were approved in the App store?

For me, my config.xml has

  android-versionCode="27"  versionCode="27"

So after I publish that version to the store (and it's approved), when I am trying to debug my next version, I have to leave these version numbers the same. If I increment them, then my in-app-purchases do not work (since that newer "version" has not been approved to access that feature).

I only increment the version numbers when I do the final build just prior to uploading to the store.

Just a shot-in-the-dark as to what your issue may be....

sunnycupertino commented 7 years ago

Can you tell me your app id?