折叠式横幅广告

折叠式横幅广告是一种横幅广告,最初以较大的叠加层形式展示,并带有一个按钮,可将此类广告收起为最初请求的横幅广告尺寸。折叠式横幅广告旨在提升锚定广告(尺寸较小的锚定广告)的效果。本指南介绍了如何为现有横幅广告展示位置启用折叠式横幅广告。

前提条件

实现

确保您的横幅广告视图使用您希望用户在常规(已收起)横幅广告状态下看到的尺寸来定义。在广告请求中添加 extras 参数,并以 collapsible 作为键,并以广告的展示位置作为值。

折叠式展示位置定义了展开区域如何锚定到横幅广告。

Placement 行为 预期用例
top 展开的广告的顶部与折叠广告的顶部对齐。 广告位于屏幕的顶部。
bottom 展开后广告的底部与收起后广告的底部对齐。 广告位于屏幕底部。

如果加载的广告是折叠式横幅广告,则在将其置于视图层次结构中后,横幅广告会立即显示折叠式叠加层。

void _loadAd() async {
  // Replace these test ad units with your own ad units.
  final String adUnitId = Platform.isAndroid
    ? 'ca-app-pub-3940256099942544/2014213617'
    : 'ca-app-pub-3940256099942544/8388050270';

  // Get the size before loading the ad.
  final size = await AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
      MediaQuery.sizeOf(context).width.truncate());

  if (size == null) {
    // Unable to get the size.
    return;
  }

  // Create an extra parameter that aligns the bottom of the expanded ad to the
  // bottom of the banner ad.
  const adRequest = AdRequest(extras: {
    "collapsible": "bottom",
  });

  BannerAd(
      adUnitId: adUnitId,
      request: adRequest,
      size: size,
      listener: const BannerAdListener()
  ).load();
}

广告刷新行为

  import 'package:uuid/uuid.dart';

  // Generate a UUID.
  String uuidString = const Uuid().v4();

  final adRequest = AdRequest(extras: {
    "collapsible": "bottom",
    "collapsible_banner_id": uuidString,
  });

如果您稍后希望在会话中加载另一个折叠式横幅广告,可以使用包含折叠式参数的请求手动调用 loadAd()

检查已加载的广告是否可折叠

调用 isCollapsible 以检查加载的最后一个横幅广告是否是可折叠的。如果请求无法加载且上一个横幅广告可折叠,API 会返回 true。

中介

折叠式横幅广告在 Beta 版期间仅适用于 Google 需求。通过 AdMob 中介 投放的广告显示为常规的不可折叠横幅广告。

广告投放行为

为了最大限度提升横幅广告的效果,不支持更大尺寸的折叠式叠加层的广告可以返回一些折叠式横幅广告请求,并立即以常规横幅广告尺寸呈现。