如果您打算將公開評估功能與自訂原生廣告格式搭配使用, 不包含影片素材資源,請自行呼叫 評估 API對多媒體類型自訂原生廣告的開啟評估功能 只有 7.43.0 以上版本才支援格式。如果你使用的是自訂區域 包含影片素材資源的原生廣告格式,則您不需要遵循此 指南,Google Mobile Ads SDK 可追蹤影片素材資源的可視度 管理。
必要條件
- Google Mobile Ads SDK 7.44.0 以上版本。
- 請參閱「Open Measurement 結合行動廣告」一文 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
時,您需要登錄自訂廣告
透過 GADNativeTemplateAd
使用 displayAdMeasurement.view
的檢視畫面
資源。
您也必須明確告知 SDK 才能開始評估廣告。方法如下
對應用程式的 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 認證 程序。