流星:在流星应用中包含Admob非页内广告 [英] Meteor: Including Admob Interstitial ads in Meteor app
问题描述
我一直在借助以下问题在Meteor应用程序中实施Admob广告: Admob问题
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?
如何在Meteor Apps中实现它们?
How do you implement them in Meteor Apps?
推荐答案
方法应类似于此处公开的方法: https://github.com/appfeel/admob-google-cordova/wiki/requestInterstitialAd
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);
如果是非页内广告,只需确保它显示在您想要的时刻即可,您可以致电它与 autoShowIntesrtitial:false
并实现事件侦听器:
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);
}
});
您还可以实现 admob.events.onAdFailedToLoad
并检查错误代码并根据错误代码进行检查, 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.
这篇关于流星:在流星应用中包含Admob非页内广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!