Display-type Custom Native Ad Formats and Open Measurement

  • Open Measurement is required for custom native ad formats without video assets, utilizing the Open Measurement APIs in Google Mobile Ads SDK version 7.43.0 or later.

  • For display-type custom native ad formats, IAB certification as a Measurement Provider is necessary for certified measurement results.

  • To implement Open Measurement, you must use Google Mobile Ads SDK 7.44.0 or higher, integrate custom native ad formats, configure a viewability provider, and register your ad view for tracking.

  • Loading an ad remains the same with Open Measurement, requiring you to register your custom ad view and initiate measurement using the startWithError method.

If you plan to use open measurement with custom native ad formats that don't contain a video asset, you'll be responsible for calling the Open Measurement APIs yourself. Open measurement for display-type custom native ad formats is only supported by version 7.43.0 and later. If you're using custom native ad formats with a video asset, you don't need to follow this guide—the Google Mobile Ads SDK tracks viewability of the video asset on your behalf.

Prerequisites

Load an ad

Loading an ad is the same whether you're using open measurement or not. In this case we'll use a simple ViewController to demonstrate loading a GADNativeCustomFormatAd:

@interface OpenMeasurementNativeCustomFormatAdViewController ()
    <GADNativeCustomFormatAdLoaderDelegate> {
  IBOutlet UIView *_parentView;
  GADAdLoader *_adLoader;
  GADNativeCustomFormatAd *_customTemplateAd;
  MySimpleNativeAdView *_simpleNativeAdView;
}

@end

@implementation OpenMeasurementNativeCustomFormatAdViewController

- (void) viewDidLoad {
  [super viewDidLoad];

  _adLoader = [[GADAdLoader alloc] initWithAdUnitID:@"your ad unit ID"
                                 rootViewController:self
                                            adTypes:@[ kGADAdLoaderAdTypeNativeCustomFormat ]
                                            options:nil];
  _adLoader.delegate = self;
  [self loadAd];
}

- (void) loadAd {
  GAMRequest *request = [GAMRequest request];
  [_adLoader loadRequest:request];
}
...
@end

Register your view and begin measuring

When you show a GADNativeCustomFormatAd, you need to register your custom ad view with the GADNativeTemplateAd using the displayAdMeasurement.view property.

You also need to explicitly tell the SDK to begin measuring your ad. To do this, call the startWithError: method on the displayAdMeasurement property of your GADNativeCustomFormatAd. startWithError: must be called from the main thread, and subsequent calls have no effect.

@implementation OpenMeasurementNativeCustomFormatAdViewController
...
#pragma mark - GADNativeCustomFormatAdLoaderDelegate

- (void) adLoader:(GADAdLoader *) adLoader
    didReceiveNativeCustomFormatAd:(GADNativeCustomFormatAd *)nativeCustomFormatAd {
  NSLog(@"Received custom native ad: %@", nativeCustomFormatAd);

  _customTemplateAd = nativeCustomFormatAd;

  // Put the custom native ad on screen.
  _simpleNativeAdView =
    [[NSBundle mainBundle] loadNibNamed:@"SimpleCustomNativeAdView"
                                  owner:nil
                                options:nil]
    .firstObject;
  [_parentView addSubview:_simpleNativeAdView];
  [_simpleNativeAdView populateWithCustomNativeAd:_customTemplateAd];

  // Set the top-level native ad view on the GADNativeCustomFormatAd so the
  // Google Mobile Ads SDK can track viewability for that view.
  _customTemplateAd.displayAdMeasurement.view = _simpleNativeAdView;
  // Begin measuring your impressions and clicks.
  NSError *error = nil;
  [_customTemplateAd.displayAdMeasurement startWithError:&error];

  if (error) {
    NSLog(@"Failed to start the display measurement.");
  }
}
...
@end

That's all there is to it. Once you release your app you will begin receiving measurement data, however your data won't be certified until you go through the IAB certification process.