Meteor:在Meteor应用程序中包含Admob插页式广告

时间:2016-02-09 13:44:06

标签: javascript meteor admob interstitial

我一直致力于在Meteor应用程序中使用以下问题来实施Admob广告:Admob Question

有没有办法为活动实施插页式广告?我可以使用calla功能来激活广告吗?它只是设置为设置横幅广告吗?

如何在Meteor Apps中实现它们?

1 个答案:

答案 0 :(得分:1)

方式应该与此处公开的方式类似: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调用它,然后实现事件监听器:

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);

小心这个用户案例:用户离开应用程序(可能会导致一些问题)。确保它在所有情况下都能正常工作。