內嵌自動調整橫幅廣告

選取平台: Android iOS Flutter

自動調整橫幅廣告可透過設定廣告寬度,由系統計算出最佳尺寸。此外,這類廣告能根據不同裝置的特性,調整為最適合的大小,有助於提升成效。

內嵌自動調整橫幅廣告的高度可變,版面比錨定自動調整橫幅廣告更大、更高。這類廣告的高度會依情況調整,可能與螢幕等高,或在您指定的高度上限內。

您可以將內嵌自動調整橫幅廣告放在可捲動的內容中,例如:

示意圖:自動調整橫幅廣告和內嵌自動調整橫幅廣告的差異

事前準備

繼續操作前,請確認您完成以下事項:

導入自動調整橫幅廣告

與錨定自動調整橫幅廣告不同,內嵌自動調整橫幅廣告載入時,會使用內嵌自動調整橫幅廣告大小。如要建立內嵌自動調整廣告大小,請完成下列步驟:

  1. 取得目前裝置的寬度;如果不想使用螢幕全寬,也可以自行設定寬度。

  2. 依廣告大小類別使用適當的靜態方法 (例如 GADCurrentOrientationInlineBannerAdSizeWithWidth(CGFloat width)),取得所選螢幕方向的內嵌自動調整廣告大小物件。

    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(AdSizeBanner)]
    
    // Step 3: Load an ad.
    let request = AdManagerRequest()
    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.
    

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

    • 內嵌自動調整橫幅廣告以最大可用寬度顯示時,效果最佳。這通常是指裝置螢幕的全寬,或橫幅廣告上層內容的完整寬度。請務必掌握廣告所在檢視區塊的寬度、裝置螢幕寬度、上層內容寬度,並考量應保留的安全區域。
    • 您可能需要更新或建立新的委刊項,才能支援自動調整大小。瞭解詳情

    設定內嵌自動調整橫幅廣告的方向

    如要預先載入特定方向的內嵌自動調整橫幅廣告,請使用下列方法:

    如果應用程式同時支援直向與橫向顯示,而您想預先載入符合目前螢幕方向的自動調整橫幅廣告,請使用 GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(CGFloat width)。這個方法會依照當前螢幕方向載入廣告。

    限制內嵌自動調整橫幅廣告的高度

    根據預設,如果例項化的內嵌自動調整橫幅廣告未指定 maxHeight 值,maxHeight 會等於裝置高度。如要限制內嵌自動調整橫幅廣告的高度,請使用 GADInlineAdaptiveBannerAdSizeWithWidthAndMaxHeight(CGFloat width, CGFloat maxHeight) 方法。

    其他資源

    GitHub 範例程式碼

    下載範例應用程式,即可查看內嵌自動調整橫幅廣告的實際效果。

    Swift Objective-C