Meteor: Including Admob Interstitial ads in Meteor app

风流意气都作罢 提交于 2019-12-10 23:02:11

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/35293653/meteor-including-admob-interstitial-ads-in-meteor-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!