I've been working on implementing Admob ads in my Meteor application with the help of the following question: Admob Question
Is there a way to implement interstitial ads for an event? Can I just calla function that activates the ad and is it just setup like setting banner ads?
How do you implement them in Meteor Apps?
The way should be similar than what is exposed here: https://github.com/appfeel/admob-google-cordova/wiki/requestInterstitialAd
admob.requestInterstitialAd({
publisherId: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
interstitialAdId: "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII",
tappxIdiOs: "/XXXXXXXXX/Pub-XXXX-iOS-IIII",
tappxIdAndroid: "/XXXXXXXXX/Pub-XXXX-Android-AAAA",
tappxShare: 0.5,
adSize: admob.AD_SIZE.SMART_BANNER,
bannerAtTop: false,
overlap: false,
offsetStatusBar: false,
isTesting: false,
adExtras : {},
autoShowBanner: true,
autoShowInterstitial: true
}, success, fail);
If it is about interstitials, just to ensure it is shown at the moment you want, you can call it with autoShowIntesrtitial: false
and then implement the event listener:
var isInterstitialAvailable = false;
// Launch your app
if (Meteor.isCordova && window.admob) {
document.addEventListener('deviceready', function () {
myAppRequestInterstitial();
});
}
// Request interstitial, when your app is launched and after an interstitial has been shown to request the next one
function myAppRequestInterstitial() {
admob.requestInterstitialAd({
publisherId: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
interstitialAdId: "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII",
adSize: admob.AD_SIZE.SMART_BANNER,
autoShowInterstitial: false
}, success, fail);
}
// Get noticed if there is an interstitial prepared to be shown
document.addEventListener(admob.events.onAdLoaded, function (e) {
if (e.adType == admob.AD_TYPE.INTERSTITIAL) {
isInterstitialAvailable = true;
}
});
// This is the function called by your event
function myEvent() {
if (isInterstitialAvailable && isSomeOtherCondition) {
admob.showInterstitialAd(success, fail);
}
}
// Request next interstitial
document.addEventListener(admob.events.onAdOpened, function (e) {
if (e.adType == admob.AD_TYPE.INTERSTITIAL) {
isInterstitialAvailable = false;
admob.requestInterstitialAd(options, success, fail);
}
});
You could also implement admob.events.onAdFailedToLoad
and check for error code and depending on it, setTimeout(myAppRequestInterstitial, howManyMs);
Be carefull with this user case: user leaving the app (it can cause some problems). Just ensure it works fine in all cases.