Android iOS Unity JS API 常见问题

插屏广告2.0

简介

基本信息

插屏广告是移动广告的一种常见形式,在应用开流程中弹出,当应用展示插页式广告时,用户可以选择点按广告,访问其目标网址,也可以将其关闭,返回应用。插屏2.0广告和插屏广告相比,只需要进行简单的切换,就可以在保证当前插屏渲染效果的前提下提升广告价格和填充率(注:插屏2.0接入需要在开发者平台创建插屏2.0广告位)
权限等级:开放

适用场景:在应用执行流程的自然停顿点,适合投放这类广告

分类:插屏2.0广告分为小规格图文(弹窗)、小规格纯图片(弹窗)和大规格纯图片(竖屏)、插屏横屏视频、插屏竖屏视频,具体种类可以在开发者平台进行选择:

小规格图文(弹窗) 小规格纯图片(弹窗) 大规格纯图片(竖屏)
插屏横屏视频 插屏竖屏视频

主要API

生命周期事件回调

您可以实现全部或部分GDTUnifiedInterstitialAdDelegate,以跟踪点击成功或者插屏2.0广告请求失败等广告生命周期事件。

@protocol GDTUnifiedInterstitialAdDelegate <NSObject>
@optional
- (void)unifiedInterstitialSuccessToLoadAd:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
- (void)unifiedInterstitialFailToLoadAd:(GDTUnifiedInterstitialAd *)unifiedInterstitial error:(NSError *)error
- (void)unifiedInterstitialFailToPresent:(GDTUnifiedInterstitialAd *)unifiedInterstitial error:(NSError *)error
- (void)unifiedInterstitialWillPresentScreen:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
- (void)unifiedInterstitialDidPresentScreen:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
- (void)unifiedInterstitialDidDismissScreen:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
- (void)unifiedInterstitialWillLeaveApplication:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
- (void)unifiedInterstitialWillExposure:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
- (void)unifiedInterstitialClicked:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
- (void)unifiedInterstitialAdWillPresentFullScreenModal:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
- (void)unifiedInterstitialAdDidPresentFullScreenModal:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
- (void)unifiedInterstitialAdWillDismissFullScreenModal:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
- (void)unifiedInterstitialAdDidDismissFullScreenModal:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
- (void)unifiedInterstitialAd:(GDTUnifiedInterstitialAd *)unifiedInterstitial playerStatusChanged:(GDTMediaPlayerStatus)status;
- (void)unifiedInterstitialAdViewWillPresentVideoVC:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
- (void)unifiedInterstitialAdViewDidPresentVideoVC:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
- (void)unifiedInterstitialAdViewWillDismissVideoVC:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
- (void)unifiedInterstitialAdViewDidDismissVideoVC:(GDTUnifiedInterstitialAd *)unifiedInterstitial;
@end

其中,视频播放过程中,会有如下几种状态

枚举变量 枚举含义
GDTMediaPlayerStatusInitial 初始状态
GDTMediaPlayerStatusLoading 加载中
GDTMediaPlayerStatusStarted 开始播放
GDTMediaPlayerStatusPaused 用户行为导致暂停
GDTMediaPlayerStatusStoped 播放停止
GDTMediaPlayerStatusError 播放出错

在实现上述事件回调之前,请务必先设置delegate:

Objective-C
self.interstitial.delegate = self;
Swift
interstitial.delegate = self

回调函数列表

回调函数名 回调函数含义
unifiedInterstitialSuccessToLoadAd 插屏2.0广告预加载成功回调
unifiedInterstitialFailToLoadAd 插屏2.0广告预加载失败回调
unifiedInterstitialWillPresentScreen 插屏2.0广告将要展示回调
unifiedInterstitialDidPresentScreen 插屏2.0广告视图展示成功回调
unifiedInterstitialDidDismissScreen 插屏2.0广告展示结束回调
unifiedInterstitialFailToPresent 插屏2.0广告播放失败回调
unifiedInterstitialWillLeaveApplication 当点击下载应用时会调用系统程序打开其它App或者Appstore时回调
unifiedInterstitialWillExposure 插屏2.0广告曝光回调
unifiedInterstitialClicked 插屏2.0广告点击回调
unifiedInterstitialAdWillPresentFullScreenModal 点击插屏2.0广告以后即将弹出全屏广告页
unifiedInterstitialAdDidPresentFullScreenModal 点击插屏2.0广告以后弹出全屏广告页
unifiedInterstitialAdWillDismissFullScreenModal 插屏2.0全屏广告页将要关闭
unifiedInterstitialAdDidDismissFullScreenModal 插屏2.0全屏广告页被关闭
unifiedInterstitialAd:playerStatusChanged 插屏2.0视频广告 player 播放状态更新回调
unifiedInterstitialAdViewWillPresentVideoVC 插屏2.0视频广告详情页将要展示
unifiedInterstitialAdViewDidPresentVideoVC 插屏2.0视频广告详情页已经展示
unifiedInterstitialAdViewWillDismissVideoVC 插屏2.0视频广告详情页将要消失
unifiedInterstitialAdViewDidDismissVideoVC 插屏2.0视频广告详情页已经消失

接入代码示例

加载并显示插屏2.0广告

1.在您的View Controller文件中,引入对应头文件,定义好UnifiedInterstitial对象以及定义清本类支持GDTUnifiedInterstitialAdDelegate协议,如下例所示:

Objective-C
  #import "GDTUnifiedInterstitialAd.h"
  @interface UnifiedInterstitialViewController () <GDTUnifiedInterstitialAdDelegate>
  @property (nonatomic, strong) GDTUnifiedInterstitialAd *interstitial;
Swift
   class UnifiedInterstitialViewController: UIViewController,GDTUnifiedInterstitialAdDelegate {
   private var interstitial: GDTUnifiedInterstitialAd?
    ...
  }

2.在需要加载插屏2.0广告的逻辑处,初始化interstitial变量,并做相应展示。

Objective-C
- (IBAction)loadAd:(id)sender {
    if (self.interstitial) {
        self.interstitial.delegate = nil;
    }
    self.interstitial = [[GDTUnifiedInterstitialAd alloc] initWithPlacementId:YOUR_PLACEMENT_ID];
    self.interstitial.delegate = self;
    self.interstitial.videoMuted = self.videoMutedSwitch.on; // 设置视频是否Mute
    self.interstitial.videoAutoPlayOnWWAN = self.videoAutoPlaySwitch.on; // 设置视频是否在非 WiFi 网络自动播放
    self.interstitial.maxVideoDuration = (NSInteger)self.maxVideoDurationSlider.value;  // 如果需要设置视频最大时长,可以通过这个参数来进行设置

    [self.interstitial loadAd];
}

- (IBAction)showAd:(id)sender {
    [self.interstitial presentAdFromRootViewController:self];
}
Swift
@IBAction func loadAd(_ sender: Any) {
    if (interstitial != nil) {
        interstitial?.delegate = nil
        interstitial = nil
    }
    interstitial = GDTUnifiedInterstitialAd.init(placementId: YOUR_PLACEMENT_ID)
    interstitial?.delegate = self

    interstitial?.load()
}

@IBAction func showAd(_ sender: Any) {
    interstitial?.present(fromRootViewController: self)
}

3.将YOUR_PLACEMENT_ID替换成你自己的PLACEMENTID。

注意

  • 在一次展现完成后,需要再次调用loadAd方法来加载新的广告,用于下次展现。
  • 关于释放,建议在释放ViewController之前将_interstitialObj的delegate属性设置为nil

加载并显示插屏2.0全屏视频广告

1.在您的View Controller文件中,引入对应头文件,定义好UnifiedInterstitial对象以及定义清本类支持GDTUnifiedInterstitialAdDelegate协议,如下例所示:

Objective-C
  #import "GDTUnifiedInterstitialAd.h"
  @interface UnifiedInterstitialViewController () <GDTUnifiedInterstitialAdDelegate>
  @property (nonatomic, strong) GDTUnifiedInterstitialAd *interstitial;

2.在需要加载插屏2.0全屏视频广告的逻辑处,初始化interstitial变量,并做相应展示。

Objective-C
- (IBAction)loadAd:(id)sender {
    if (self.interstitial) {
        self.interstitial.delegate = nil;
    }
    self.interstitial = [[GDTUnifiedInterstitialAd alloc] initWithPlacementId:YOUR_PLACEMENT_ID];
    self.interstitial.delegate = self;
    self.interstitial.videoMuted = self.videoMutedSwitch.on; // 设置视频是否Mute
    [self.interstitial loadFullScreenAd]; // 加载插屏2.0全屏视频广告
}

- (IBAction)showAd:(id)sender {
    [self.interstitial presentFullScreenAdFromRootViewController:self]; // 展示插屏2.0全屏视频广告
}

3.将YOUR_PLACEMENT_ID替换成你自己的PLACEMENTID。

注意

  • 在一次展现完成后,需要再次调用loadAd方法来加载新的广告,用于下次展现。
  • 关于释放,建议在释放ViewController之前将_interstitialObj的delegate属性设置为nil

在不展示插屏2.0广告时执行调试

在您的ViewController里实现如下回调,处理插屏2.0广告加载失败的问题:

Objective-C
- (void)unifiedInterstitialFailToLoadAd:(GDTUnifiedInterstitialAd *)unifiedInterstitial error:(NSError *)error
{
    NSLog(@"interstitial fail to load, Error : %@",error);
}
Swift
  func unifiedInterstitialFail(toLoad unifiedInterstitial: GDTUnifiedInterstitialAd, error: Error) {
        print(#function)
  }

多阶底价能力

接入多阶底价能力分2步:

step1:

找优量汇运营同学开通广告位的多阶底价权限并提供底价配置信息;

step2:

当广告拉取成功后,通过GDTUnifiedInterstitialAd类的eCPMLevel属性查看当前广告对应的底价层级。

/**
 返回广告的eCPM等级

 @return 成功返回一个包含数字的string,比如@"2"表示底价等级为2,@""或nil表示无权限或后台异常
 */
@property (nonatomic, readonly) NSString *eCPMLevel;

Copyright © 1998 - 2020 Tencent Inc. All Rights Reserved.
腾讯公司 版权所有 | 加入优量汇