內嵌自動調整橫幅廣告

自動調整橫幅廣告是新一代的回應式廣告,可根據各種裝置的廣告大小進行最佳化,藉此提升成效。自動調整橫幅廣告僅支援固定高度,改善了固定大小的橫幅廣告,讓開發人員指定廣告的寬度,並據此決定最適合的廣告大小。

為了挑選最適合的廣告大小,內嵌自動調整橫幅廣告會採用最大高度,而非固定高度。進而提升成效。

使用內嵌自動調整橫幅廣告的時機

與錨定自動調整橫幅廣告相比,內嵌自動調整橫幅廣告會尺寸更大、圖示也更高。它們的高度可變,高度與裝置螢幕高度一樣。

並用在捲動內容中,例如:

必要條件

  • Google Mobile Ads SDK 8.10.0 以上版本

事前準備

在應用程式中導入自動調整橫幅廣告時,請注意以下幾點:

  • 您必須知道廣告刊登時的檢視畫面寬度,並應考量裝置寬度和所有適用的安全區域

  • 確認您使用的是最新版的 Google Mobile Ads SDK;如果您使用中介服務,則必須使用最新版本的中介服務轉接程式。

  • 內嵌自動調整橫幅廣告大小在充分利用可用寬度時,成效最佳。在多數情況下,這會是使用中裝置螢幕的最大寬度。請務必考量適用的安全區域。

  • 您可能需要更新或建立新的委刊項,才能採用自動調整大小。瞭解詳情

導入作業

導入內嵌自動調整橫幅廣告的步驟與導入錨定自動調整橫幅廣告的步驟相同。唯一的差別在於內嵌自動調整橫幅廣告的大小是以內嵌自動調整橫幅廣告大小載入。如何建立內嵌自動調整廣告大小:

  • 取得使用中的裝置寬度;如果不想用整個螢幕寬度,也可以自行設定寬度。
  • 在廣告大小類別中使用適當的靜態方法,例如: GADCurrentOrientationInlineBannerAdSizeWithWidth(CGFloat width) ,取得所選螢幕方向的內嵌自動調整廣告大小物件。
  • 如要限制橫幅廣告高度,可以使用靜態方法 GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight(CGFloat width, CGFloat maxHeight)

以下程式碼範例會示範這些步驟:

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 = GAMBannerView(adSize: adSize)
bannerView.adUnitID = "ad unit ID"
bannerView.rootViewController = self

// For Ad Manager, the `adSize` property is used for the adaptive banner ad
// size. The `validAdSizes` property is used as normal for the supported
// reservation sizes for the ad placement.
bannerView.validAdSizes = [NSValueFromGADAdSize(GADAdSizeBanner)]

// Step 3: Load an ad.
let request = GAMRequest()
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.
GAMBannerView bannerView = [[GAMBannerView alloc] initWithAdSize:adSize];
bannerView.adUnitID = @"ad unit ID";
bannerView.rootViewController = self;

// For Ad Manager, the adSize property is used for the adaptive banner ad size.
// The validAdSizes property is used as normal for the supported reservation
// sizes for the ad placement. This is optional and only needed if you wish to
// support reservation ad sizes.
bannerView.validAdSizes = @[ NSValueFromGADAdSize(GADAdSizeBanner) ];

// Step 3: Load an ad.
GAMRequest *request = [GAMRequest request];
[bannerView loadRequest:request];
// TODO: Insert banner view in table view or scroll view, etc.

其他資源

GitHub 上的範例

下載範例應用程式,瞭解內嵌自動調整橫幅廣告的實際運作情形。

Swift Objective-C