【问题标题】:Admob fix for PhonegapPhonegap 的 Admob 修复程序
【发布时间】:2018-11-12 23:59:08
【问题描述】:

我应该把setInterval(showInterstitialAd, 120000);放在哪里?我想使用下面的代码使用 admob 在我的 phonegap 应用上每 2 分钟创建一次插页式广告。我使用以下插件:<gap:plugin name="phonegap-admob" source="npm"/>

var isPendingInterstitial = false;
var isAutoshowInterstitial = false;

function prepareInterstitialAd() {
if (!isPendingInterstitial) {
        admob.requestInterstitialAd({
            autoShowInterstitial: isAutoshowInterstitial
        });
    }
}

function onAdLoadedEvent(e) {
    if (e.adType === admob.AD_TYPE.INTERSTITIAL && !isAutoshowInterstitial) {
        isPendingInterstitial = true;
    }
}

function onDeviceReady() {
    document.removeEventListener('deviceready', onDeviceReady, false);

    admob.setOptions({
        publisherId:          "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",
        interstitialAdId:     "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII",
    });

    document.addEventListener(admob.events.onAdLoaded, onAdLoadedEvent);
    prepareIntestitialAd();
}

document.addEventListener("deviceready", onDeviceReady, false);

function showInterstitialAd() {
    if (isPendingInterstitial) {
        admob.showInterstitialAd(function () {
                isPendingInterstitial = false;
                isAutoshowInterstitial = false;
                prepareInterstitialAd();
        });
    } else {
        // The interstitial is not prepared, so in this case, we want to show     the interstitial as soon as possible
        isAutoshowInterstitial = true;
        admob.requestInterstitialAd({
            autoShowInterstitial: isAutoshowInterstitial
        });
    }
}

【问题讨论】:

    标签: javascript android cordova admob


    【解决方案1】:

    不建议每次都显示插页式广告,因为 Google 可能会认为这是“意外启动的插页式广告”(请参阅​​ https://support.google.com/admob/answer/6201362)。更建议显示与用户操作相关的插页式广告(即登录后、游戏开始或结束时等)

    也就是说,你应该把它放在onAdClosed。在此处查看有关如何集成它的完整示例:https://github.com/appfeel/admob-google-cordova/wiki/showInterstitialAd

    function onAdClosed(e) {
      if (isAppForeground) {
        if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
          setTimeout(admob.requestInterstitialAd, 1000 * 60 * 2);
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多