自動調整橫幅廣告是新一代的回應式廣告 根據裝置調整廣告大小,有效提升廣告成效。改善固定大小 橫幅廣告是僅支援固定高度的橫幅廣告 自動調整橫幅廣告則可讓開發人員 指定廣告大小,並利用這項資訊判斷最合適的廣告大小。
為了挑選最合適的廣告大小,內嵌自動調整橫幅廣告會使用最大值,而非固定大小 這麼做可以提升效能。
內嵌自動調整橫幅廣告的使用時機
與錨定自動調整橫幅廣告相比,內嵌自動調整橫幅廣告較大、尺寸更加大 橫幅廣告它們的高度不一,而且可以和裝置螢幕一樣高。
這類廣告主要用於捲動內容中,例如:
必要條件
- Google Mobile Ads SDK 8.10.0 以上版本
事前準備
在應用程式中導入自動調整橫幅廣告時,請注意以下幾點:
您必須知道廣告擺放的檢視畫面寬度,以及 請將裝置寬度和任何 。
確認您使用的是最新版的 Google Mobile Ads SDK 使用中介服務 (最新版的中介服務轉接程式)。
內嵌自動調整橫幅廣告大小經過精心設計,能夠 完整可用寬度。在大多數情況下,這會是 顯示所用裝置的螢幕畫面。請務必考量適用的安全區域。
取得廣告大小的方法包括:
使用內嵌自動調整橫幅廣告 API 時,系統會導入 Google Mobile Ads SDK 會傳回指定寬度和
GADAdSize
內嵌旗標。高度為 0 或maxHeight
,視 您使用的 API廣告可以放送時, 。內嵌自動調整橫幅廣告是專為放置在可捲動內容中。 橫幅尺寸可以是裝置螢幕的高度,也可以受限於高度上限 會因 API 而異
導入作業
導入內嵌自動調整橫幅廣告的步驟與步驟相同 導入錨定自動調整橫幅廣告。唯一的差別是內嵌 系統會使用內嵌自動調整橫幅廣告大小載入自動調整橫幅廣告。目的地: 建立內嵌自動調整廣告大小:
- 取得所用裝置的寬度,或者,如果您不想自行設定寬度 使用整個螢幕寬度
- 針對廣告尺寸類別使用適當的靜態方法,例如
GADCurrentOrientationInlineBannerAdSizeWithWidth(CGFloat width)
取得所選方向的內嵌自動調整廣告大小物件。 - 如要限制橫幅廣告的高度,可以使用靜態方法
GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight(CGFloat width, CGFloat maxHeight)
,直接在 Google Cloud 控制台實際操作。
以下程式碼範例示範了這些步驟:
Swift
// Step 1: Create an inline adaptive banner ad size. This size is used to
// request your adaptive banner. You can pass in the width of the device, or
// set your own width. This example sets a static width.
let adSize = GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(320)
// Step 2: Create banner with the inline size and set ad unit ID.
let bannerView = GADBannerView(adSize: adSize)
bannerView.adUnitID = "<var>ad unit ID</var>"
bannerView.rootViewController = self
// Step 3: Load an ad.
let request = GADRequest()
bannerView.load(request)
// TODO: Insert banner view in table view or scroll view, etc.
Objective-C
// Step 1: Create an inline adaptive banner ad size. This size is used to
// request your adaptive banner. You can pass in the width of the device, or set
// your own width. This example sets a static width.
GADAdSize *adSize = GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(320);
// Step 2: Create banner with the inline size and set ad unit ID.
GADBannerView bannerView = [[GADBannerView alloc] initWithAdSize:adSize];
bannerView.adUnitID = @"<var>ad unit ID</var>";
bannerView.rootViewController = self;
// Step 3: Load an ad.
GADRequest *request = [GADRequest request];
[bannerView loadRequest:request];
// TODO: Insert banner view in table view or scroll view, etc.
其他資源
GitHub 上的範例
下載範例應用程式,瞭解內嵌自動調整橫幅廣告的實際運作情形。