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

광고용 Web View API를 사용하면 앱 신호를 WKWebView하여 콘텐츠를 제공하고 광고주를 스팸으로부터 보호한 게시자입니다. 이러한 앱 신호(예: 앱 ID, 앱 버전)는 보고서를 활성화하는 데 도움이 됩니다. 및 인앱 브라우저 인벤토리 타겟팅을 선택합니다. 앱 트래픽에서만 사용할 수 있는 사용 사례입니다.

작동 방식

Google 모바일 광고 SDK와의 통신은 광고에 대한 응답으로만 발생합니다. 다음 중 하나로 트리거되는 이벤트:

SDK는 등록된 SDK에 메시지 핸들러를 WKWebView 하여 이러한 광고 이벤트를 수신할 수 있습니다. 더 나은 서비스를 위해 소스 코드에서 테스트 페이지로 이동합니다.

기본 요건

  • Google 모바일 광고 SDK 버전 9.6.0 이상
  • 다음 키와 문자열 값으로 Info.plist 파일을 업데이트합니다. 이 Google 모바일 광고 SDK가 광고를 구현하는 개발자에게 적용되는 GADApplicationIdentifier 값 액세스할 수 있습니다. 이 단계를 완료하지 못하여 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 게시자 태그. 이 해야 할 일과 같이 가능한 한 빨리 뷰 컨트롤러의 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에서 동의를 수집하세요. 웹 뷰 API는 광고는 모바일 앱 컨텍스트에서 수집된 동의를 IAB TCF v2.0 또는 IAB CCPA 규정 준수 프레임워크를 웹 뷰의 태그에 추가합니다. 관심이 있으시다면 Ad Exchange와 애드센스의 소유자로서 단일 동의 절차를 WKWebView 및 이에 상응하는 웹 콘텐츠는 동의 관리 플랫폼을 사용하여 WKWebView 컨텍스트입니다