cordova-plugin-admob-free
cordova-plugin-admob-free copied to clipboard
No error in console But Ads are not showing
i followed steps according to this website https://ionicframework.com/docs/native/admob-free
when i run on my mobile no error is showing but ads are not displaying. what could be the issue here..?
I am facing same issue.
me too on Android API level 30. working fine on API level 24.
um.. I don't know if this is a good answer to your question. I am using Android API level 26 ~ 29.
Based on Cordova Gradle Version : 6.5 Android Gradle plugin Version : 4.1.1
If it doesn't work well, please leave a comment. I'll test it on Ionic too.
Try the code below.
//index.html
<script type="text/javascript" src="js/admob.js"></script>
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log("##### hello world");
initAd();
showRewardVideo();
}
</script>
//admob.js
var admob = null;
var admobId = {
android: {
banner: 'ca-app-pub-5814442187791081/4051889481',
interstitial: 'ca-app-pub-5814442187791081/7059188595',
rewardvideo: 'ca-app-pub-5814442187791081/3302764656',
},
ios: {
banner: 'ca-app-pub-3940256099942544/6300978111',
interstitial: 'ca-app-pub-3940256099942544/1033173712',
rewardvideo: 'ca-app-pub-3940256099942544/5224354917',
}
}
function initAd() {
admob = window.plugins.admob || window.admob;
if (/(android)/i.test(navigator.userAgent) && admob) {
admob.banner.config({
id: admobId.android.banner,
autoShow: false,
});
admob.banner.prepare();
admob.interstitial.config({
id: admobId.android.interstitial,
autoShow: false,
});
admob.interstitial.prepare();
admob.rewardvideo.config({
id: admobId.android.rewardvideo,
autoShow: false,
});
admob.rewardvideo.prepare();
} else if (/(ipod|iphone|ipad)/i.test(navigator.userAgent) && admob) {
admob.banner.config({
id: admobId.ios.banner,
autoShow: false,
});
admob.banner.prepare();
admob.interstitial.config({
id: admobId.ios.interstitial,
autoShow: false,
});
admob.interstitial.prepare();
admob.rewardvideo.config({
id: admobId.ios.rewardvideo,
autoShow: false,
});
admob.rewardvideo.prepare();
}
var interstitialEvent = ['LOAD_FAIL', 'CLOSE', 'EXIT_APP'];
interstitialEvent.forEach((v) => {
document.addEventListener(`admob.interstitial.events.${v}`, function () {
admob.interstitial.prepare();
})
})
var rewardvideoEvent = ['LOAD_FAIL', 'CLOSE', 'EXIT_APP', 'REWARD'];
rewardvideoEvent.forEach((v) => {
document.addEventListener(`admob.rewardvideo.events.${v}`, function () {
admob.rewardvideo.prepare();
})
})
}
function showBanner() {
if (admob) {
admob.banner.show();
}
}
function removeBanner() {
if (admob) {
admob.banner.remove();
setTimeout(() => {
admob.banner.prepare()
}, 100)
}
}
function prepareInterstitial() {
if (admob) {
admob.interstitial.prepare();
}
}
function showInterstitial() {
if (admob) {
admob.interstitial.show();
}
}
function prepareRewardVideo() {
if (admob) {
admob.rewardvideo.prepare();
}
}
function showRewardVideo() {
if (admob) {
admob.rewardvideo.show();
}
}