如果您打算在不含影片素材資源的自訂原生廣告格式中使用開放評估功能,就必須自行呼叫 Open Measurement API。多媒體廣告類型自訂原生廣告格式的開放式評估僅適用於 7.43.0 以上版本。如果搭配影片素材資源使用自訂原生廣告格式,則不需要遵循本指南的說明,因為 Google Mobile Ads SDK 會代您追蹤影片素材資源的可視度。
必要條件
- Google Mobile Ads SDK 7.44.0 以上版本。
- 參閱「使用行動廣告 SDK 進行 Open Measurement」一文。
- 整合自訂原生廣告格式。
- 設定可視度評估服務供應商,並指派給委刊項。
- 在 Ad Manager UI 中建立自訂格式時,輸入合作夥伴名稱。
載入廣告
無論是否使用開放式評估,載入廣告都是一樣的。在此情況下,我們會使用簡單的 ViewController
來展示載入 GADNativeCustomTemplateAd
:
@interface OpenMeasurementNativeCustomTemplateAdViewController ()
<GADNativeCustomTemplateAdLoaderDelegate> {
IBOutlet UIView *_parentView;
GADAdLoader *_adLoader;
GADNativeCustomTemplateAd *_customTemplateAd;
MySimpleNativeAdView *_simpleNativeAdView;
}
@end
@implementation OpenMeasurementNativeCustomTemplateAdViewController
- (void) viewDidLoad {
[super viewDidLoad];
_adLoader = [[GADAdLoader alloc] initWithAdUnitID:@"your ad unit ID"
rootViewController:self
adTypes:@[ kGADAdLoaderAdTypeNativeCustomTemplate ]
options:nil];
_adLoader.delegate = self;
[self loadAd];
}
- (void) loadAd {
GAMRequest *request = [GAMRequest request];
[_adLoader loadRequest:request];
}
...
@end
註冊檢視表並開始評估
顯示 GADNativeCustomTemplateAd
時,您必須使用 displayAdMeasurement.view
屬性,使用 GADNativeTemplateAd
註冊自訂廣告檢視畫面。
您也需要明確指示 SDK 開始評估廣告。方法是對 GADNativeCustomTemplateAd
的 displayAdMeasurement
屬性呼叫 startWithError:
方法。您必須從主執行緒呼叫 startWithError:
,後續呼叫不會產生任何作用。
@implementation OpenMeasurementNativeCustomTemplateAdViewController
...
#pragma mark - GADNativeCustomTemplateAdLoaderDelegate
- (void) adLoader:(GADAdLoader *) adLoader
didReceiveNativeCustomTemplateAd:(GADNativeCustomTemplateAd *)nativeCustomTemplateAd {
NSLog(@"Received custom native ad: %@", nativeCustomTemplateAd);
_customTemplateAd = nativeCustomTemplateAd;
// 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 GADNativeCustomTemplateAd 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 認證程序後,資料才能通過認證。