插屏广告

插屏广告一般采用全屏或整页形式,会暂时覆盖应用的整个界面,通常出现在应用自然的暂停或过渡节点,例如游戏关卡完成后、主要视图切换时等。

以下各节将向您介绍如何加载和显示插屏广告。

加载插屏广告

以下代码展示了如何附加事件监听器以及加载第一则插屏广告:

var interstitialAdUnitId:String = "«ad-unit-ID»";
var retryAttempt:Number;

public function initializeInterstitialAds():void
{
  // Attach event callbacks
  AppLovinMAXEvents.setInterstitialLoadedEvent(onInterstitialLoaded);
  AppLovinMAXEvents.setInterstitialLoadFailedEvent(onInterstitialLoadFailed);
  AppLovinMAXEvents.setInterstitialDisplayedEvent(onInterstitialDisplayed);
  AppLovinMAXEvents.setInterstitialFailedToDisplayEvent(onInterstitialFailedToDisplay);
  AppLovinMAXEvents.setInterstitialClickedEvent(onInterstitialClicked);
  AppLovinMAXEvents.setInterstitialHiddenEvent(onInterstitialHidden);

  // Load the first interstitial
  loadInterstitial();
}

private function loadInterstitial()
{
  AppLovinMAX.loadInterstitial(interstitialAdUnitId);
}

private function onInterstitialLoaded(adEventInfo:AdEventInfo):void
{
  // Interstitial ad is ready for you to show. AppLovinMAX.isInterstitialReady(adUnitId) now returns 'true'

  // Reset retry attempt
  retryAttempt = 0;
}

private function onInterstitialLoadFailed(adEventInfo:AdEventInfo):void
{
  // Interstitial ad failed to load
  // AppLovin recommends that you retry with exponentially higher delays, up to a maximum delay (in this case 64 seconds)

  retryAttempt++;
  var retryDelay:Number = Math.pow(2, Math.min(6, retryAttempt));

  var timer:Timer = new Timer(retryDelay, 1);
  timer.addEventListener(TimerEvent.TIMER, loadInterstitial);
  timer.start();
}

private function onInterstitialDisplayed(adEventInfo:AdEventInfo):void {}

private function onInterstitialFailedToDisplay(adEventInfo:AdEventInfo):void
{
  // Interstitial ad failed to display. AppLovin recommends that you load the next ad.
  loadInterstitial();
}

private static function onInterstitialClicked(adEventInfo:AdEventInfo):void {}

private function onInterstitialHidden(adEventInfo:AdEventInfo):void
{
  // Interstitial ad is hidden. Pre-load the next ad.
  loadInterstitial();
}

显示插屏广告

调用 showInterstitial() 以显示插屏广告:

if (AppLovinMAX.isInterstitialReady(«ad-unit-ID»))
{
  AppLovinMAX.showInterstitial(«ad-unit-ID»)
}

这篇文章有帮助吗?
这篇文章有帮助吗?
search