Native Ads Express

This guide shows you how to use the Google Mobile Ads SDK to display AdMob Native Express ads in iOS applications. It covers things like how to add a GADNativeExpressAdView to a layout, how to request ads, and so on.

Prerequisites

This guide assumes some working knowledge of the Google Mobile Ads SDK. If you haven't already done so, consider running through Get Started.

What's a Native Express Ad?

Native Express ads are similar to banners in that they're rectangular ads that you can drop into a storyboard and size how you like. The key difference is that you, the publisher, can control the ad's presentation details (things like image sizes, fonts, colors, and so on) by uploading a CSS template for your ad unit. AdMob combines that template with advertiser assets like icons, images, and text, and displays the results in a GADNativeExpressAdView. This approach minimizes the amount of mobile code needed for a Native Express ad, while helping publishers display ads that look natural in their app.

Create a Native Express ad unit

Native Express ad units are created at apps.admob.com. For an overview of the format and more information on choosing a template size for your ad units, see Overview of native ads express. For more information on how to create CSS to give your Native Express ads a natural, unobtrusive style, see the Guide to custom CSS for native ads express.

GADNativeExpressAdView

The GADNativeExpressAdView class is responsible for requesting and displaying Native Express ads. You can add one to a storyboard and assign constraints to it, much as one would with a GADBannerView.

Choose a size

Rather than forcing publishers to choose between fixed sizes, Native Express ads offer several template sizes (chosen when creating an ad unit), each with a range of height and width values:

Template size Min width Max width Min height Max height
Small 280 1200 80 612
Medium 280 1200 132 1200
Large 280 1200 250 1200

A publisher who wants to display a "Medium" template size can use widths between 280 and 1200 dp, and heights from 132 to 1200 dp. That means that 300 by 200, 450 by 150, and 613 by 572 are all valid for the Medium template size. Bear in mind, though, that not all sizes are likely to make for a good presentation. While it's technically possible to request a "Small" template with a size of 1200 by 80, it's probably not the best choice! Also, be sure to consider the screen dimensions of the device on which you're displaying the ad. Larger sizes should generally be reserved for presentation on tablets.

Apps aren't required to use the same size for every request. The same ad unit could be requested with one size in portrait orientation and another in landscape, or in different sizes according to the particular device it's running on. In the event that an app makes a request with an ad size that falls outside the range for the ad unit's template, though, an error is returned.

Publishers can also use the GADAdSizeFullWidthPortraitWithHeight() and GADAdSizeFullWidthLandscapeWithHeight() methods when programmatically creating a GADAdSize for a GADNativeExpressAdView. In this case, the ad occupies the entire width of the device screen.

At this time, the Fluid size should not be used with Native Ads Express.

Load an ad

Loading ads is done through the loadRequest: method in the GADNativeExpressAdView class. Before calling it, make sure the adUnitID and rootViewContoller properties have been assigned prior to loading an ad.

If you have a UIViewController with a GADNativeExpressAdView in its storyboard, here's how you can set the properties and load an ad:

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController {
  @IBOutlet weak var nativeExpressAdView: GADNativeExpressAdView!

  override func viewDidLoad() {
    super.viewDidLoad()
    nativeExpressAdView.adUnitID = "ca-app-pub-3940256099942544/2562852117"
    nativeExpressAdView.rootViewController = self

    let request = GADRequest()
    nativeExpressAdView.load(request)
  }
}

Objective-C

#import "ViewController.h"

@import GoogleMobileAds;

@interface ViewController ()

@property(nonatomic, weak) IBOutlet GADNativeExpressAdView *nativeExpressAdView;

@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  self.nativeExpressAdView.adUnitID = @"ca-app-pub-3940256099942544/2562852117";
  self.nativeExpressAdView.rootViewController = self;

  GADRequest *request = [GADRequest request];
  [self.nativeExpressAdView loadRequest:request];
}

@end

Native video

In addition to images, text, and numbers, some native ads contain video assets. At the current time, this is limited to the App Install format, but may be extended to Content ads in the future.

To simplify the configuration and display of video, the Mobile Ads SDK provides the following video-related classes for Native Ads Express:

GADVideoOptions

The GADVideoOptions class allows apps to configure how native video assets should behave. GADVideoOptions objects can be assigned to a GADNativeExpressAdView via the setAdOptions method:

Swift

let videoOptions = GADVideoOptions()
videoOptions.startMuted = true
nativeExpressAdView.setAdOptions([videoOptions])

Objective-C

GADVideoOptions *videoOptions = [[GADVideoOptions alloc] init];
videoOptions.startMuted = true;
[self.nativeExpressAdView setAdOptions:@[ videoOptions ]];

The GADVideoOptions class currently offers one property, startMuted, which tells the SDK whether video assets should start in a muted state. The default value is true.

GADVideoController

The GADVideoController class is used to retrieve information about video assets. GADNativeExpressAdView offers a videoController property that exposes the GADVideoController for its ads. This property is never nil, even when the ad doesn't contain a video asset.

GADVideoController offers the following methods for querying video state:

  • hasVideoContent - True if the ad includes a video asset, false otherwise.
  • aspectRatio - The aspect ratio of the video (width/height), or zero if no video asset is present.

In addition, apps can set a GADViewControllerDelegate for the GADViewController to be notified of events in the lifecycle of a video asset. GADViewControllerDelegate offers a single optional message, videoControllerDidEndVideoPlayback, which is sent when a video completes playback.

Here's an example of GADViewControllerDelegate in action:

Swift

class ViewController: UIViewController,
    GADVideoControllerDelegate {

  override func viewDidLoad() {
    ...
      nativeExpressAdView.videoController.delegate = self
    ...
  }

  func videoControllerDidEndVideoPlayback(_ videoController: GADVideoController!) {
    // Here apps can take action knowing video playback is finished.
    // This is handy for things like unmuting audio, and so on.
  }
}

Objective-C

@interface ViewController () 

- (void)viewDidLoad {
  ...
  self.nativeExpressAdView.videoController.delegate = self;
  ...
}

...

- (void)videoControllerDidEndVideoPlayback:(GADVideoController *)videoController {
  // Here apps can take action knowing video playback is finished.
  // This is handy for things like unmuting audio, and so on.
}

@end

Next steps

For more information on the best ways to use Native Express ads, check out these resources:

  • To explore targeting capabilities of banner ads, check out Targeting.
  • To learn about ad events and ad delegates, check out Ad Events.
  • To see a Native Express ad in action, download our sample project from GitHub.

Send feedback about...

AdMob by Google
AdMob by Google