Reputation: 163
I'm trying to put AdMob ads into my ionic android apps and to test the functionality I made an ionic app called AdMobTest. The plugin I'm using is the cordova-admob-pro plugin. Here is my AdMob code:
var admobid = {};
if (/(android)/i.test(navigator.userAgent)) { //Android
admobid = {
banner : 'ca-app-pub-2586564966169402/9782816366',
interstitial : 'ca-app-pub-2586564966169402/8345912938',
gotHereMsg1 : 'banner and interstitial have the android IDs'
};
} else if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)) { //iOS
admobid = {
banner : 'Stand in iOS banner ID',
interstitial: 'stand in iOS interstitial ID',
gotHereMsg1 : 'banner and interstitial have the iOS IDs'
};
} else { //Neither
admobid = {
gotHereMsg1 : 'banner and interstitial have no IDs'
}
}
if (window.AdMob) {
var admob = window.AdMob;
admob.createBanner ({
adId : admobid.banner,
position : admob.AD_POSITION.BOTTOM_CENTER,
isTesting : false, //False for live ; True for production
autoShow : true
});
admob.prepareInterstitial ({
adId : admobid.interstitial,
autoShow : false
});
gotHereMsg2 = "window.AdMob is true";
} else {
gotHereMsg2 = "window.AdMob is not true";
}
//Got an ID and the actual ID's
document.getElementById("getIdCheck").innerHTML = admobid.gotHereMsg1;
document.getElementById("bannerId").innerHTML = admobid.banner;
document.getElementById("interstitialId").innerHTML = admobid.interstitial;
//window.AdMob is true and banner is created + interstitial is prepared
document.getElementById("isWindowAdmob").innerHTML = gotHereMsg2;
//Show interstitial function is executed or has not been executed
document.getElementById("startInterstitial").onclick = function () {
if (window.AdMob) {
var admob = window.AdMob;
admob.showInterstitial();
gotHereMsg3 = "Show Interstitial function has been executed";
} else {
gotHereMsg3 = "Show Interstitial function has not been executed";
}
document.getElementById("checkInterstitial").innerHTML = gotHereMsg3;
}
To show what works I kept in the tests I did using the "gotHereMsg" variables. All the variables get where I want them to go.
So gotHereMsg1 has the msg about android IDs and the IDs are also correct.
gotHereMsg2 returns "window.AdMob is true" which means the createBanner and prepareInterstitial function are being executed.
Lastly gotHereMsg3 returns "Show Interstitial function has been executed" when I click the button.
Even though all the functions are being executed and it obviously recognizes window.AdMob no banners are being shown. Hopefully this provides enough information to resolve this.
It might be worth noting that I am using ionicv1 and that the code is written in the ionic's app.js file under the $ionicPlatform.ready function.
Upvotes: 1
Views: 1381
Reputation: 2165
I have plenty of experience with admob and ionic v1.
First, dont use cordova-admob-pro, they (he?) literally steals revenue from you! tuns of proof here
if (window.admob !== undefined) {
admob.banner.config({
id: 'ca-app-pub-...',
autoShow: true
});
// Create banner
admob.banner.prepare();
// Show the banner
admob.banner.show();
admob.interstitial.config({
id: 'ca-app-pub-....',
autoShow: false
});
admob.interstitial.prepare();
}
Second I don't really see anything wrong...
I'd advise you to run the admob commands in the browser console windows while using remote inspect.....
and at same time watch the adb logcat
to see if you get "NO FILL" or any other admob error
Upvotes: 5