折叠式横幅广告
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
折叠式横幅广告最初会以较大的叠加层形式展示,并提供一个可将其折叠为最初请求的横幅广告尺寸的按钮。折叠式横幅广告旨在提升锚定广告的效果,而锚定广告具有较小的尺寸。本指南介绍了如何为现有的横幅广告展示位置启用折叠式横幅广告。

前提条件
植入
确保为横幅广告视图指定的尺寸是您希望用户在常规(已折叠)横幅广告状态下看到的尺寸。在广告请求中添加一个 extra 参数,其中 collapsible
为键,广告的展示位置为值。
可折叠展示位置定义了展开区域如何锚定到横幅广告。
Placement 值
|
行为 |
预期应用场景 |
top |
广告展开后的顶部与广告折叠后的顶部对齐。 |
广告位于界面顶部。 |
bottom |
广告展开后的底部与广告折叠后的底部对齐。 |
广告位于界面底部。 |
如果加载的广告是折叠式横幅广告,则在放置到视图层次结构中后,它会立即显示可折叠的叠加层。
Swift
func loadBannerAd() {
bannerView.adUnitID = "ca-app-pub-3940256099942544/8388050270"
bannerView.rootViewController = self
let viewWidth = FRAME_WIDTH
bannerView.adSize = currentOrientationAnchoredAdaptiveBanner(width: viewWidth)
let request = AdManagerRequest
// Create an extra parameter that aligns the bottom of the expanded ad to
// the bottom of the bannerView.
let extras = Extras()
extras.additionalParameters = ["collapsible" : "bottom"]
request.register(extras)
bannerView.load(request)
}
Objective-C
- (void)loadBannerAd {
self.bannerView.adUnitID = @"ca-app-pub-3940256099942544/8388050270";
CGFloat viewWidth = FRAME_WIDTH;
self.bannerView.adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth);
GADRequest *request = [GADRequest request];
// Create an extra parameter that aligns the bottom of the expanded ad to the
// bottom of the bannerView.
GADExtras *extras = [[GADExtras alloc] init];
extras.additionalParameters = @{@"collapsible" : @"bottom"};
[request registerAdNetworkExtras:extras];
[self.bannerView loadRequest:request];
}
广告刷新行为
对于在 Ad Manager 网页界面中为横幅广告配置了自动刷新功能的应用,我们设定了以下规则:如果已针对横幅广告位请求加载折叠式横幅广告,那么后续广告刷新将不再请求加载此类广告。这是因为在每次刷新时都显示折叠式横幅广告可能会对用户体验造成负面影响。
如果您希望在会话的稍晚时间再加载一个折叠式横幅广告,可以使用包含 collapsible 参数的请求手动加载广告。
检查加载的广告是否可折叠
为实现最佳广告效果,对于折叠式横幅广告请求,可以返回非折叠式横幅广告。您可以调用 isCollapsible
来检查上次加载的广告是否为折叠式广告。如果加载请求失败,但上一个横幅广告是折叠式广告,该 API 仍会返回 true。
Swift
func bannerViewDidReceiveAd(_ bannerView: BannerView) {
print("The last loaded banner is \(bannerView.isCollapsible ? "" : "not") collapsible.")
}
Objective-C
- (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
NSLog(@"The last loaded banner is %@collapsible.", (bannerView.isCollapsible ? @"" : @"not "));
}
折叠式横幅广告仅适用于 Google 需求来源。通过中介投放的广告会显示为常规的非折叠式横幅广告。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-25。
[null,null,["最后更新时间 (UTC):2025-08-25。"],[[["\u003cp\u003eCollapsible banner ads start as larger overlays and can be collapsed to a standard banner size, improving performance for smaller anchored ads.\u003c/p\u003e\n"],["\u003cp\u003eTo implement, define the banner view's collapsed size and include an extras parameter in the ad request specifying the placement (\u003ccode\u003etop\u003c/code\u003e or \u003ccode\u003ebottom\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eWhile auto-refresh is enabled, subsequent refreshes after a collapsible banner won't request another collapsible banner to avoid impacting user experience.\u003c/p\u003e\n"],["\u003cp\u003eYou can verify if a loaded ad is collapsible by calling \u003ccode\u003eisCollapsible\u003c/code\u003e on the banner view.\u003c/p\u003e\n"],["\u003cp\u003eDuring the beta period, collapsible banner ads are only supported for Google demand and not for ads served through mediation.\u003c/p\u003e\n"]]],[],null,["Select platform: [Android](/ad-manager/mobile-ads-sdk/android/banner/collapsible \"View this page for the Android platform docs.\") [iOS](/ad-manager/mobile-ads-sdk/ios/banner/collapsible \"View this page for the iOS platform docs.\") [Unity](/ad-manager/mobile-ads-sdk/unity/banner/collapsible \"View this page for the Unity platform docs.\") [Flutter](/ad-manager/mobile-ads-sdk/flutter/banner/collapsible \"View this page for the Flutter platform docs.\")\n\n\u003cbr /\u003e\n\nCollapsible banner ads are banner ads that are initially presented as a larger\noverlay, with a button to collapse them to the originally requested banner size.\nCollapsible banner ads are intended to improve performance of anchored ads that\nare otherwise a smaller size. This guide shows how to turn on collapsible banner\nads for existing banner placements.\n\nPrerequisites\n\n- Complete the [banner ads get started guide](/ad-manager/mobile-ads-sdk/ios/banner).\n\nImplementation\n\nMake sure your banner view is defined with the size you would like users to see\nin the regular (collapsed) banner state. Include an extras parameter in the ad\nrequest with `collapsible` as the key and the placement of the ad as the value.\n\nThe collapsible placement defines how the expanded region anchors to the banner\nad.\n\n| `Placement` value | Behavior | Intended use case |\n|-------------------|-------------------------------------------------------------------------|-----------------------------------------------|\n| `top` | The top of the expanded ad aligns to the top of the collapsed ad. | The ad is placed at the top of the screen. |\n| `bottom` | The bottom of the expanded ad aligns to the bottom of the collapsed ad. | The ad is placed at the bottom of the screen. |\n\nIf the loaded ad is a collapsible banner, the banner shows the collapsible\noverlay immediately once it's placed in the view hierarchy.\n\nSwift \n\n func loadBannerAd() {\n bannerView.adUnitID = \"ca-app-pub-3940256099942544/8388050270\"\n bannerView.rootViewController = self\n let viewWidth = FRAME_WIDTH\n bannerView.adSize = currentOrientationAnchoredAdaptiveBanner(width: viewWidth)\n\n let request = AdManagerRequest\n\n // Create an extra parameter that aligns the bottom of the expanded ad to\n // the bottom of the bannerView.\n let extras = Extras()\n extras.additionalParameters = \\[\"collapsible\" : \"bottom\"\\]\n request.register(extras)\n\n bannerView.load(request)\n }\n\nObjective-C \n\n - (void)loadBannerAd {\n self.bannerView.adUnitID = @\"ca-app-pub-3940256099942544/8388050270\";\n CGFloat viewWidth = FRAME_WIDTH;\n self.bannerView.adSize = GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(viewWidth);\n\n GADRequest *request = [GADRequest request];\n\n // Create an extra parameter that aligns the bottom of the expanded ad to the\n // bottom of the bannerView.\n GADExtras \\*extras = \\[\\[GADExtras alloc\\] init\\];\n extras.additionalParameters = @{@\"collapsible\" : @\"bottom\"};\n \\[request registerAdNetworkExtras:extras\\];\n\n [self.bannerView loadRequest:request];\n }\n\n\u003cbr /\u003e\n\nAds refreshing behavior\n\nFor apps that configure auto-refresh for banner ads in the\nAd Manager web interface, when a collapsible banner ad\nis requested for a banner slot, subsequent ad refreshes won't request\ncollapsible banner ads. This is because showing a collapsible banner on every\nrefresh could have a negative impact on user experience.\n\nIf you want to load another collapsible banner ad later in the session, you can\nload an ad manually with a request containing the collapsible parameter.\n\nCheck if a loaded ad is collapsible\n\nNon-collapsible banner ads are eligible to return for collapsible banner\nrequests to maximize performance. Call `isCollapsible` to check if the last\nbanner loaded is collapsible. If the request fails to load and the previous\nbanner is collapsible, the API returns true. \n\nSwift \n\n func bannerViewDidReceiveAd(_ bannerView: BannerView) {\n print(\"The last loaded banner is \\(bannerView.isCollapsible ? \"\" : \"not\") collapsible.\")\n }\n\nObjective-C \n\n - (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {\n NSLog(@\"The last loaded banner is %@collapsible.\", (bannerView.isCollapsible ? @\"\" : @\"not \"));\n }\n\n\u003cbr /\u003e\n\nMediation\n\nCollapsible banner ads are only available for Google demand. Ads served through\nmediation show as normal, non-collapsible banner ads."]]