在 ionic android 平台上放置有趣广告的正确方法

Right way of placing interestitial ad in ionic android platform

为了在我的 android 应用程序(我使用 ionic 制作)中展示有趣的广告,我使用了以下代码:

<script type="text/javascript">
function runads(){
document.addEventListener("deviceready", onDeviceReady, false);
}

function initAds() {
if (admob) {
  var adPublisherIds = {
    ios : {
      banner : "###############",
      interstitial : "##################"
    },
    android : {
      banner : "#############",
      interstitial : "#########################"
    }
  };

  var admobid = (/(android)/i.test(navigator.userAgent)) ? adPublisherIds.android : adPublisherIds.ios;

  admob.setOptions({
    publisherId:      admobid.banner,
    interstitialAdId: admobid.interstitial,
    tappxIdiOs:       "/XXXXXXXXX/Pub-XXXX-iOS-IIII",
    tappxIdAndroid:   "/XXXXXXXXX/Pub-XXXX-Android-AAAA",
    tappxShare:       0.5
  });

  registerAdEvents();

} else {
  alert('AdMobAds plugin not ready');
}
}

 function onAdLoaded(e) {
if (e.adType === admob.AD_TYPE.INTERSTITIAL) {
  admob.showInterstitialAd();
  showNextInterstitial = setTimeout(function() {
    admob.requestInterstitialAd();
  }, 2 * 60 * 1000); // 2 minutes
}
}

 // optional, in case respond to events
 function registerAdEvents() {
document.addEventListener(admob.events.onAdLoaded, onAdLoaded);
document.addEventListener(admob.events.onAdFailedToLoad, function (e) {});
document.addEventListener(admob.events.onAdOpened, function (e) {});
document.addEventListener(admob.events.onAdClosed, function (e) {});
document.addEventListener(admob.events.onAdLeftApplication, function (e) {});
document.addEventListener(admob.events.onInAppPurchaseRequested, function (e) {});
}

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

// display a banner at startup
admob.createBannerView();

// request an interstitial
admob.requestInterstitialAd();
}

我的兴趣广告使用此 code.Then 完美展示,我已将其上传到 google play store.suddenly 我收到了来自 google Admob 团队关于兴趣广告的消息广告投放。消息是-

Hello,We are alerting you that your app is currently in violation of the AdMob program policies. Importantly, this will require action on your part to ensure no disruption in ad serving. Please read below for more information on the actions you need to take:

Violation explanation

LAYOUT ENCOURAGES ACCIDENTAL CLICKS - INTERSTITIAL ADS:Publishers are not permitted to encourage users to click AdMob interstitial ads in any way. Please review how you’ve implemented interstitial ads and be mindful of the following non-compliant implementation(s):Interstitial ads that load unexpectedly while a user is viewing the app’s content.For more information about our policies and tips for how to comply please read the following:

Interstitial ads that load unexpectedly while a user is viewing the app’s content.For more information about our policies and tips for how to comply please read the following:AdMob ad placement policyAdMob interstitial ad guidanceAdMob preload instructions for Android and iOSAction required: Please make changes immediately to your app to comply with AdMob program policies.Current account status: ActiveYou do not need to contact us once you've made the necessary changes to your app. Please be aware that if additional violations are accrued, ad serving may be disabled to the app listed above.Note that the app listed above is just one example and the same violation may exist on other apps you own. We suggest that you review all your apps for compliance with the AdMob program policies to reduce the likelihood of future warnings.For more information regarding our policy warning notifications, visit our Help Center.Thank you for your cooperation.Sincerely,The Google AdMob Team

我该如何解决这个问题?

可能是插屏广告的加载需要一些时间,所以你需要规划插屏的加载,确保插屏在你需要展示的时候可用。如果没有,启动 admob.showInterstitialAd() 将加载插页式广告并在可用时显示它(因为标志 autoShowInterstitial 默认为 true,请参阅 https://github.com/appfeel/admob-google-cordova/wiki/setOptions)。

有关如何规划插页式广告的完整示例:https://github.com/appfeel/admob-google-cordova/wiki/showInterstitialAd

基本上,您所做的就是请求插页式广告并让应用知道插页式广告是否可用。可能你的离子代码应该是这样的:

angular.module('myApp', ['admobModule'])

    .constant('AdmobConfig', {
        bannerId: /(android)/i.test(navigator.userAgent) ? "ca-app-pub-XXXXXXXXXXXXXXXX/ANDROID_BANNER_ID" : "ca-app-pub-XXXXXXXXXXXXXXXX/IOS_BANNER_ID",
        interstitialId: /(android)/i.test(navigator.userAgent) ? "ca-app-pub-XXXXXXXXXXXXXXXX/ANDROID_INTERSTITIAL_ID" : "ca-app-pub-XXXXXXXXXXXXXXXX/IOS_INTERSTITIAL_ID",
    })

    .config(function (admobSvcProvider, AdmobConfig) {
        admobSvcProvider.setOptions({
            publisherId: AdmobConfig.bannerId,
            interstitialAdId: AdmobConfig.interstitialId,
            autoShowInterstitial: false,
        });
    })

    .run(function ($rootScope, $ionicPlatform, $timeout, admobSvc) {
        admobSvc.requestInterstitialAd();

        $rootScope.isInterstitialAvailable = false;
        $rootScope.isAppForeground = false;

        $rootScope.$on(admobSvc.events.onAdLoaded, function onAdLoaded(evt, e) {
            if ($rootScope.isAppForeground) {
                if (e.adType === admobSvc.AD_TYPE.INTERSTITIAL) {
                    $rootScope.isInterstitialAvailable = true;
                }
            }
        });

        $rootScope.$on(admobSvc.events.onAdOpened, function onAdOpened(evt, e) {
            if ($rootScope.isAppForeground) {
                if (e.adType === admobSvc.AD_TYPE.INTERSTITIAL) {
                    $rootScope.isInterstitialAvailable = false;
                    $timeout(admobSvc.requestInterstitialAd, 1); // Immediately request next interstitial asap
                }
            }
        });

        $ionicPlatform.on('pause', function onPause() {
            if ($rootScope.isAppForeground) {
                $rootScope.isAppForeground = false;
            }
        });
        $ionicPlatform.on('resume', function onResume() {
            if (!$rootScope.isAppForeground) {
                $timeout(admobSvc.requestInterstitialAd, 1);
                $rootScope.isAppForeground = true;
            }
        });
    })

    .controller('YourController', function ($rootScope, admobSvc) {
        var vm = this;

        vm.pleaseShowInterstitial = function () {
            if ($rootScope.isInterstitialAvailable) {
                admobSvc.showInterstitialAd();
            }
        };
    });

另请注意,前台应用程序有一个管理。这很重要,如果不是,用户可以将应用程序置于后台,插页式广告会自动显示。在你的情况下,它不是那么相关,因为你控制何时显示插页式广告,但我建议你保留它,以防你决定开始自动显示插页式广告:)