I'm trying to implement interstitial ads in my HTML5 game using cordova-plugin-admob-free.
I use it as follows:
var ADMOB_AndroidID = (my Admob ID here);
var ADMOB_iOSID = "";
var ADMOB_WindowsID = "";
document.addEventListener( 'deviceready', initAdmob );
function initAdmob() {
var admobid = {};
if ( /(android)/i.test(navigator.userAgent) ) { // for android & amazon-fireos
admobid = {
banner: ADMOB_AndroidID,
interstitial: ADMOB_AndroidID
};
} else if ( /(ipod|iphone|ipad)/i.test(navigator.userAgent) ) { // for ios
admobid = {
banner: ADMOB_iOSID,
interstitial: ADMOB_iOSID
};
} else { // for windows phone
admobid = {
banner: ADMOB_WindowsID,
interstitial: ADMOB_WindowsID
};
}
admob.interstitial.config({
id: admobid.interstitial,
isTesting: true,
autoShow: false
})
admob.interstitial.prepare();
document.addEventListener('admob.interstitial.events.CLOSE', function(event) {
admob.interstitial.prepare();
} );
}
Then, after the game has finished, I call
admob.interstitial.show();
When I run it on the Android emulator (or on a real device), nothing happens when the game finishes and the Chrome debugger shows:
Uncaught (in promise) Interstital not ready yet
So what am I doing wrong?
EDIT: Added screenshot of Chrome Console
My console show this (after I added an eventlistener on LOAD_FAIL of the interstitial):
It just started working without me changing anything. Apparently, it takes (quite) a while for an Ad Unit to become active after it has been created. So the above code works.
Just an extra tip: I first made the mistake of using my App ID instead of the Ad Unit ID. If your ID has a tilde (~) instead of a slash (/), then you are using your App ID. Login to your AdMob account, create an Ad Unit, and use its ID instead.