可收合橫幅廣告是橫幅廣告的一種,一開始會以較大尺寸重疊在畫面上,點按廣告上的按鈕後,就會收合為原始請求的橫幅廣告大小。可收合橫幅廣告的作用,是提升原本尺寸較小的錨定廣告成效。本指南說明如何為現有的橫幅廣告刊登位置,啟用可收合橫幅廣告。
必備條件
- 完整閱讀橫幅廣告入門指南。
導入作業
請確認您已依據使用者在一般 (收合) 橫幅狀態下看到的尺寸,來定義橫幅廣告檢視區塊。接著在廣告請求中加入 extras 參數,將 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 = Request
// 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];
}
廣告重新整理行為
應用程式如果在 AdMob 網頁介面對橫幅廣告設定了自動重新整理,則一旦橫幅廣告版位請求可收合橫幅廣告,後續重新整理時就不會再請求這類廣告。這是因為若每次重新整理都顯示可收合橫幅廣告,可能會對使用者體驗造成負面影響。
如果之後想在同一工作階段再次載入可收合橫幅廣告,可以手動發送包含 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 廣告需求。透過中介服務放送的廣告,會顯示為不可收合的一般橫幅廣告。