sunnycupertino / cordova-plugin-admob-simple

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

Plugin Fails to get Ads #36

Closed zusamarehan closed 6 years ago

zusamarehan commented 6 years ago

I have implemeneted this plugin but every time I try to show a banner ad the plugins fails, and executes this function

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

In the data object there is a key called reason which is

reason : "Internal error"

My Plugin lists are

cordova-admob-sdklibs 2.1.6 "Google Mobile Ads SDK for Cordova"
cordova-plugin-admob-simple 3.3.4 "Cordova-Phonegap AdMob Plugin"
cordova-plugin-network-information 2.0.1 "Network Information"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-plugin-x-socialsharing 5.4.1 "SocialSharing"
cordova-plugin-x-toast 2.6.2 "Toast"
es6-promise-plugin 4.2.2 "Promise"

My index.js file is

var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);

    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
        this.receivedEvent('deviceready');

    },

    // Update DOM on a Received Event
    receivedEvent: function(id) {
        initAd();
        console.log('Received Event: ' + id);
        showBannerFunc();

    }
};

//initialize the goodies
function initAd(){
        if ( window.plugins && window.plugins.AdMob ) {
            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-9913464317055093/1335549399',       //PUT ADMOB ADCODE HERE
                    interstitial: 'ca-app-pub-9913464317055093/2381532599'  //PUT ADMOB ADCODE HERE
                }
            };
            var admobid = ( /(android)/i.test(navigator.userAgent) ) ? ad_units.android : 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: true, // banner will overlap webview
                offsetTopBar: false, // set to true to avoid ios7 status bar overlap
                isTesting: false, // receiving test ad
                autoShow: true // auto show interstitial ad when loaded
            });

            registerAdEvents();
        } else {
            //alert( 'admob plugin not ready' );
        }
}
//functions to allow you to know when ads are shown, etc.
function registerAdEvents() {
        document.addEventListener('onReceiveAd', function(){
            alert('onReceiveAd');
        });
        document.addEventListener('onFailedToReceiveAd', function(data){
            alert('onFailedToReceiveAd');
            console.log(data);
        });
        document.addEventListener('onPresentAd', function(){
            alert('onPresentAd');
        });
        document.addEventListener('onDismissAd', function(){
            alert('onDismissAd');
        });
        document.addEventListener('onLeaveToAd', function(){
            alert('onLeaveToAd');
         });
        document.addEventListener('onReceiveInterstitialAd', function(){
            alert('onReceiveInterstitialAd');
         });
        document.addEventListener('onPresentInterstitialAd', function(){
            alert('onPresentInterstitialAd');
        });
        document.addEventListener('onDismissInterstitialAd', function(){
            alert('onDismissInterstitialAd');
        });
    }

    //display the banner
function showBannerFunc(){
    window.plugins.AdMob.createBannerView();
}
//display the interstitial
function showInterstitialFunc(){
    window.plugins.AdMob.createInterstitialView();  //get the interstitials ready to be shown and show when it's loaded.
    window.plugins.AdMob.requestInterstitialAd();
}

app.initialize();

Can you please check about this issue?

sunnycupertino commented 6 years ago

Does it work when isTesting is set to true?

zusamarehan commented 6 years ago

No, I tried.

What is that Internal Error? Can you provide more details on that.

sunnycupertino commented 6 years ago

I don't know. Something isn't right.

zusamarehan commented 6 years ago

Tell me more about the dependencies for the plugin?