광고용 웹 뷰 API를 사용하면 WKWebView의 태그에서 앱 신호를 사용할 수 있으므로 콘텐츠를 제공한 게시자의 수익 창출을 개선하고 광고주를 스팸으로부터 보호할 수 있습니다. 앱 ID, 앱 버전과 같은 이러한 앱 신호는 앱 트래픽에서만 사용할 수 있는 보고 및 인앱 브라우저 인벤토리 타겟팅 사용 사례를 활성화하는 데 도움이 됩니다.
작동 방식
Google 모바일 광고 SDK와의 통신은 다음 중 하나에 의해 트리거된 광고 이벤트에 대한 응답으로만 발생합니다.
SDK는 이러한 광고 이벤트를 수신 대기하기 위해 등록된 WKWebView에 메시지 핸들러를 추가합니다. 작동 방식을 더 잘 이해하려면 테스트 페이지의 소스 코드를 확인하세요.
기본 요건
- Google 모바일 광고 SDK 버전 9.6.0 이상
- 다음 키와 문자열 값으로 - Info.plist파일을 업데이트합니다. 이렇게 하면 웹 뷰 외부에서 광고를 구현하는 개발자에게 적용되는- GADApplicationIdentifier값에 대해 Google 모바일 광고 SDK에서 실행하는 검사를 우회할 수 있습니다. 이 단계를 놓치고- GADApplicationIdentifier를 제공하지 않으면 앱 시작 시 Google 모바일 광고 SDK에서- GADInvalidInitializationException이 발생합니다.- <!-- Indicate Google Mobile Ads SDK usage is only for web view APIs for ads --> <key>GADIntegrationManager</key> <string>webview</string>
웹 뷰 등록
기본 스레드에서 register(_:)를 호출하여 각 WKWebView 인스턴스 내에서 애드센스 코드 또는 Google 게시자 태그의 JavaScript 핸들러와 연결합니다. 이 작업은 가능한 한 빨리 실행해야 합니다(예: 뷰 컨트롤러의 viewDidLoad 메서드에서).
Swift
import WebKit
class ViewController: UIViewController {
  var webView: WKWebView!
  override func viewDidLoad() {
    super.viewDidLoad()
    // Initialize a WKWebViewConfiguration object.
    let webViewConfiguration = WKWebViewConfiguration()
    // Let HTML videos with a "playsinline" attribute play inline.
    webViewConfiguration.allowsInlineMediaPlayback = true
    // Let HTML videos with an "autoplay" attribute play automatically.
    webViewConfiguration.mediaTypesRequiringUserActionForPlayback = []
    // Initialize the WKWebView with your WKWebViewConfiguration object.
    webView = WKWebView(frame: view.frame, configuration: webViewConfiguration)
    view.addSubview(webView)
    // Register the web view.
    MobileAds.shared.register(webView)
  }
}
Objective-C
@import WebKit;
#import "ViewController.h"
@interface ViewController ()
@property(nonatomic, strong) WKWebView *webView;
@end
@implementation ViewController
- (void)viewDidLoad {
  [super viewDidLoad];
  // Initialize a WKWebViewConfiguration object.
  WKWebViewConfiguration *webViewConfiguration = [[WKWebViewConfiguration alloc] init];
  // Let HTML videos with a "playsinline" attribute play inline.
  webViewConfiguration.allowsInlineMediaPlayback = YES;
  // Let HTML videos with an "autoplay" attribute play automatically.
  webViewConfiguration.mediaTypesRequiringUserActionForPlayback = WKAudiovisualMediaTypeNone;
  // Initialize the WKWebView with your WKWebViewConfiguration object.
  self.webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:webViewConfiguration];
  [self.view addSubview:self.webView];
  // Register the web view.
  [GADMobileAds.sharedInstance registerWebView:self.webView];
}
통합 테스트
자체 URL을 사용하기 전에 다음 URL을 로드하여 통합을 테스트하는 것이 좋습니다.
https://google.github.io/webview-ads/test/#api-for-ads-tests
다음 조건이 적용되는 경우 테스트 URL에 통합이 성공했음을 나타내는 녹색 상태 표시줄이 표시됩니다.
- WKWebView가 Google 모바일 광고 SDK에 연결됨
다음 단계
- WKWebView에서 동의를 수집합니다. 광고용 Web view API는 IAB TCF v2.0 또는 IAB CCPA 규정 준수 프레임워크를 사용하여 모바일 앱 컨텍스트에서 수집된 동의를 웹 뷰의 태그에 전파하지 않습니다.- WKWebView및 수익 창출이 사용 설정된 해당 웹 콘텐츠의 소유자로서 단일 동의 흐름을 구현하려면 동의 관리 플랫폼과 협력하여- WKWebView컨텍스트에서 동의를 수집하세요.