如果您打算将开放式衡量与 未包含视频资源,则需要调用 Open 自行衡量 API。针对“展示”类型的自定义原生广告的开放式衡量 格式仅在 7.43.0 及更高版本中受支持。如果您使用的是自定义 包含视频素材资源的原生广告格式,则无需遵循此 指南 - Google 移动广告 SDK 会跟踪 。
前提条件
- Google 移动广告 SDK 7.44.0 或更高版本。
- 请参阅针对移动广告进行开放式衡量 SDK。
- 集成自定义原生广告 格式。
- 配置可见度 提供商 并将其分配给订单项
- 创建自定义合作伙伴时,输入您的合作伙伴名称 格式。
加载广告
无论您是否使用开放式衡量,加载广告的操作都是一样的。在本课中,
我们将使用简单的 ViewController
来演示如何加载
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
注册您的视图并开始衡量
在展示GADNativeCustomFormatAd
时,您需要注册自定义广告
包含使用 displayAdMeasurement.view
的 GADNativeTemplateAd
的视图
属性。
您还需要明确告知 SDK 开始衡量您的广告。为此,
对 API 的 displayAdMeasurement
属性调用 startWithError:
方法
GADNativeCustomFormatAd
。必须从主函数调用 startWithError:
且后续调用不会产生任何影响。
@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
这就是全部内容!应用发布后 衡量数据,但在完成测试之前,我们不会认证您的数据 IAB 认证 过程。