Nếu bạn dự định sử dụng tính năng đo lường mở với các định dạng quảng cáo gốc tuỳ chỉnh không chứa tài sản video, thì bạn sẽ chịu trách nhiệm gọi API Mở Chính API đo lường. Tính năng đo lường mở cho quảng cáo gốc tuỳ chỉnh loại hiển thị các định dạng chỉ được phiên bản 7.43.0 trở lên hỗ trợ. Nếu bạn đang sử dụng định dạng quảng cáo gốc có thành phần video, thì bạn không cần làm theo hướng dẫn—SDK quảng cáo trên thiết bị di động của Google theo dõi khả năng xem của nội dung video trên cho bạn.
Điều kiện tiên quyết
- SDK Quảng cáo của Google trên thiết bị di động phiên bản 7.44.0 trở lên.
- Đọc bài viết Đo lường mở bằng quảng cáo trên thiết bị di động SDK.
- Tích hợp quảng cáo gốc tuỳ chỉnh định dạng.
- Định cấu hình khả năng xem rồi chỉ định cho mục hàng của bạn.
- Nhập tên đối tác khi tạo nhóm quảng cáo tuỳ chỉnh trong giao diện người dùng Ad Manager.
Tải một quảng cáo
Việc tải quảng cáo là giống nhau cho dù bạn đang sử dụng tính năng đo lường mở hay không. Trong phần này
Trong trường hợp này, chúng ta sẽ sử dụng một ViewController
đơn giản để minh hoạ cách tải một
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
Đăng ký lượt xem của bạn và bắt đầu đo lường
Khi hiển thị GADNativeCustomFormatAd
, bạn cần phải đăng ký quảng cáo tuỳ chỉnh của mình
thành phần hiển thị với GADNativeTemplateAd
bằng displayAdMeasurement.view
thuộc tính này.
Bạn cũng cần thông báo rõ ràng cho SDK biết để bắt đầu đo lường quảng cáo của bạn. Để thực hiện việc này,
gọi phương thức startWithError:
trên thuộc tính displayAdMeasurement
của
GADNativeCustomFormatAd
. startWithError:
phải được gọi từ
luồng và các lệnh gọi tiếp theo đều không có hiệu lực.
@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
Đó là tất cả những gì cần làm. Sau khi phát hành ứng dụng, bạn sẽ bắt đầu nhận được dữ liệu đo lường, tuy nhiên, dữ liệu của bạn sẽ không được chứng nhận cho đến khi bạn Giấy chứng nhận của IAB .