광고 수익 창출을 위한 WebView API 통합

광고용 Web View API를 사용하면WKWebView의 태그에 앱 신호를 사용할 수 있으므로 콘텐츠를 제공한 게시자의 수익 창출을 개선하고 광고주를 스팸으로부터 보호할 수 있습니다.

사용 방법

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(_:) 를 호출하여 각 인스턴스 내의 애드센스 코드 또는 Google 게시자 태그의 JavaScript 핸들러와 연결을 설정합니다. WKWebView 이 작업은 뷰 컨트롤러의 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.
    GADMobileAds.sharedInstance().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://webview-api-for-ads-test.glitch.me#api-for-ads-tests

다음 조건이 적용되는 경우 테스트 URL에 성공적인 통합의 녹색 상태 표시줄이 표시됩니다.

  • WKWebView Google 모바일 광고 SDK에 연결됨

다음 단계

  • WKWebView에서 동의를 수집하세요. 광고용 Web View API는 IAB TCF v2.0 또는 IAB CCPA 규정 준수 프레임워크를 사용하여 모바일 앱 컨텍스트에서 수집된 동의를 웹 뷰의 태그에 전파하지 않습니다.WKWebView 및 해당 웹 콘텐츠의 수익 창출 대상인 웹 콘텐츠의 소유자로 단일 동의 흐름을 구현하려면 동의 관리 플랫폼을 사용하여 WKWebView 컨텍스트에서 동의를 수집하세요.