Anuncios de banner de tamaño fijo

El SDK de anuncios de Google para dispositivos móviles admite tamaños de anuncios fijos para situaciones en las que los anuncios de banner adaptable no satisfacen tus necesidades.

En la siguiente tabla, se indican los tamaños de banner estándar.

Tamaño en dp (Ancho x Alto) Descripción Disponibilidad Constante de AdSize
320 x 50 Banner Teléfonos y tablets GADAdSizeBanner
320 x 100 Banner grande Teléfonos y tablets GADAdSizeLargeBanner
300 x 250 Rectángulo mediano de IAB Teléfonos y tablets GADAdSizeMediumRectangle
468 x 60 Banner de tamaño completo de IAB Tablets GADAdSizeFullBanner
728 x 90 Tabla de clasificación de IAB Tablets GADAdSizeLeaderboard

Para definir un tamaño de banner personalizado, utiliza el código GADAdSizeFromCGSize para establecer el tamaño:

Swift

let adSize = GADAdSizeFromCGSize(CGSize(width: 250, height: 250))

Objective‑C

GADAdSize size = GADAdSizeFromCGSize(CGSizeMake(250, 250));

Ejemplo de anuncios de banner de tamaño fijo

Swift Objective‐C

Tamaño de anuncio personalizado

Además de las unidades de anuncios estándar, Google Ad Manager te permite publicar unidades de anuncios de cualquier tamaño en una app. El tamaño del anuncio (ancho y alto) definido para una solicitud de anuncio debe coincidir con las dimensiones de la vista del anuncio (GAMBannerView) que se muestra en la app. Para configurar un tamaño personalizado, usa GADAdSizeFromCGSize.

Swift

// Define custom GADAdSize of 250x250 for GAMBannerView.
let customAdSize = GADAdSizeFromCGSize(CGSize(width: 250, height: 250))
bannerView = GAMBannerView(adSize: customAdSize)

Objective‑C

// Define custom GADAdSize of 250x250 for GAMBannerView
GADAdSize customAdSize = GADAdSizeFromCGSize(CGSizeMake(250, 250));
self.bannerView = [[GAMBannerView alloc] initWithAdSize:customAdSize];

Varios tamaños de anuncios

Ad Manager te permite especificar varios tamaños de anuncios que podrían ser aptos para publicarse en un GAMBannerView. Para usar esta función, debes seguir estos tres pasos:

  1. En la IU de Ad Manager, crea una línea de pedido segmentada para la misma unidad de anuncios que está asociada a creatividades de diferentes tamaños.

  2. En tu app, configura la propiedad validAdSizes en GAMBannerView:

    Swift

    // Define an optional array of GADAdSize to specify all valid sizes that are appropriate
    // for this slot. Never create your own GADAdSize directly. Use one of the
    // predefined standard ad sizes (such as GADAdSizeBanner), or create one using
    // the GADAdSizeFromCGSize method.
    //
    // Note: Ensure that the allocated GAMBannerView is defined with an ad size. Also note
    // that all desired sizes should be included in the validAdSizes array.
    bannerView.validAdSizes = [NSValueFromGADAdSize(GADAdSizeBanner),
        NSValueFromGADAdSize(GADAdSizeMediumRectangle),
        NSValueFromGADAdSize(GADAdSizeFromCGSize(CGSize(width: 120, height: 20)))]
    

    Objective‑C

    // Define an optional array of GADAdSize to specify all valid sizes that are appropriate
    // for this slot. Never create your own GADAdSize directly. Use one of the
    // predefined standard ad sizes (such as GADAdSizeBanner), or create one using
    // the GADAdSizeFromCGSize method.
    //
    // Note: Ensure that the allocated GAMBannerView is defined with an ad size. Also note
    // that all desired sizes should be included in the validAdSizes array.
    self.bannerView.validAdSizes = @[
        NSValueFromGADAdSize(GADAdSizeBanner),
        NSValueFromGADAdSize(GADAdSizeMediumRectangle),
        NSValueFromGADAdSize(GADAdSizeFromCGSize(CGSizeMake(120, 20)))
    ];
    
  3. Implementa el método GADAdSizeDelegate para detectar un cambio en el tamaño de los anuncios.

    Swift

    public func bannerView(_ bannerView: GADBannerView, willChangeAdSizeTo size: GADAdSize)
    

    Objective‑C

    - (void)bannerView:(GAMBannerView *)view willChangeAdSizeTo:(GADAdSize)size;
    

    Recuerda establecer el delegado antes de realizar la solicitud de un anuncio.

    Swift

    bannerView.adSizeDelegate = self
    

    Objective‑C

    self.bannerView.adSizeDelegate = self;
    

Ejemplo de varios tamaños de anuncios

Swift Objective‐C