보상형 광고

보상형 광고는 사용자에게 상호작용에 대한 대가로 제공하는 광고입니다. (인앱 리워드). 이 가이드 Ad Manager의 보상형 광고를 통합하는 방법을 iOS 앱으로 전환할 수 있습니다.

기본 요건

  • Google 모바일 광고 SDK 8.0.0 이상
  • 시작 가이드를 모두 읽어보세요.

항상 테스트 광고로 테스트

앱을 빌드하고 테스트할 때는 만들 수 있습니다. 이렇게 하지 않으면 계정이 정지될 수 있습니다.

테스트 광고를 로드하는 가장 쉬운 방법은 iOS용 테스트 전용 광고 단위 ID를 사용하는 것입니다. 보상형 광고:

/6499/example/rewarded

이 ID는 모든 요청에 대해 테스트 광고를 반환하도록 특별히 구성되었으며, 코딩, 테스트, 디버깅 중에 앱에서 자유롭게 사용할 수 있습니다. 원하는 대로 앱을 게시하기 전에 이 ID를 자체 광고 단위 ID로 바꿔야 합니다.

모바일 광고 SDK의 테스트 광고가 작동하는 방식을 자세히 알아보려면 테스트 광고를 참조하세요.

구현

보상형 광고를 통합하는 기본 단계는 다음과 같습니다.

  • 광고 로드
  • [선택사항] SSV 콜백 확인
  • 콜백 등록
  • 광고 표시 및 리워드 이벤트 처리

광고 로드

광고는 정적 loadWithAdUnitID:request:completionHandler: 메서드를 GADRewardedAd 클래스. 로드 방법에서는 광고 단위 ID, GAMRequest 객체 및 완료 핸들러 광고 로드에 성공하거나 실패할 때 호출됩니다. 로드된 완료 시 GADRewardedAd 객체가 매개변수로 제공됩니다. 처리됩니다. 다음 예는 다음에서 GADRewardedAd를 로드하는 방법을 보여줍니다. ViewController 클래스

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController {

  private var rewardedAd: GADRewardedAd?

  func loadRewardedAd() {
    do {
      rewardedAd = try await GADRewardedAd.load(
        withAdUnitID: "/6499/example/rewarded", request: GAMRequest())
    } catch {
      print("Rewarded ad failed to load with error: \(error.localizedDescription)")
    }
  }
}

Objective-C

@import GoogleMobileAds;
@import UIKit;

@interface ViewController ()

@property(nonatomic, strong) GADRewardedAd *rewardedAd;

@end

@implementation ViewController
- (void)loadRewardedAd {
  GAMRequest *request = [GAMRequest request];
  [GADRewardedAd
      loadWithAdUnitID:@"/6499/example/rewarded"
                request:request
      completionHandler:^(GADRewardedAd *ad, NSError *error) {
        if (error) {
          NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
          return;
        }
        self.rewardedAd = ad;
        NSLog(@"Rewarded ad loaded.");
      }];
}

[선택사항] 서버 측 확인 (SSV) 콜백 확인

서버 측에서 추가 데이터가 필요한 앱 확인 콜백은 보상형 광고의 맞춤 데이터 기능입니다. 보상형 광고에 설정된 모든 문자열 값 객체가 SSV 콜백의 custom_data 쿼리 매개변수에 전달됩니다. 답이 '아니요'인 경우 맞춤 데이터 값이 설정되면 custom_data 쿼리 매개변수 값이 SSV 콜백에 있어야 합니다

다음 코드 샘플은 보상형 광고에 맞춤 데이터를 설정하는 방법을 보여줍니다. 객체를 반환합니다.

Swift

do {
  rewardedAd = try await GADRewardedAd.load(
    withAdUnitID: "/6499/example/rewarded", request: GAMRequest())
  let options = GADServerSideVerificationOptions()
  options.customRewardString = "SAMPLE_CUSTOM_DATA_STRING"
  rewardedAd.serverSideVerificationOptions = options
} catch {
  print("Rewarded ad failed to load with error: \(error.localizedDescription)")
}

Objective-C

[GADRewardedAd
     loadWithAdUnitID:@"/6499/example/rewarded"
              request:[GAMRequest request];
    completionHandler:^(GADRewardedAd *ad, NSError *error) {
      if (error) {
        // Handle Error
        return;
      }
      self.rewardedAd = ad;
      GADServerSideVerificationOptions *options =
          [[GADServerSideVerificationOptions alloc] init];
      options.customRewardString = @"SAMPLE_CUSTOM_DATA_STRING";
      ad.serverSideVerificationOptions = options;
    }];

콜백 등록

프레젠테이션 이벤트에 대한 알림을 받으려면 다음을 구현해야 합니다. GADFullScreenContentDelegate 프로토콜을 사용하여 반환된 광고의 fullScreenContentDelegate 속성입니다. 이 GADFullScreenContentDelegate 프로토콜은 광고가 및 해제되었을 때를 확인할 수 있습니다. 다음 코드는 프로토콜을 구현하여 광고에 할당하는 방법을 보여줍니다.

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController, GADFullScreenContentDelegate {

  private var rewardedAd: GADRewardedAd?

  func loadRewardedAd() {
    do {
      rewardedAd = try await GADRewardedAd.load(
        withAdUnitID: "/6499/example/rewarded", request: GAMRequest())
      rewardedAd?.fullScreenContentDelegate = self
    } catch {
      print("Rewarded ad failed to load with error: \(error.localizedDescription)")
    }
  }

  /// Tells the delegate that the ad failed to present full screen content.
  func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
    print("Ad did fail to present full screen content.")
  }

  /// Tells the delegate that the ad will present full screen content.
  func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("Ad will present full screen content.")
  }

  /// Tells the delegate that the ad dismissed full screen content.
  func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("Ad did dismiss full screen content.")
  }
}

Objective-C

@interface ViewController () <GADFullScreenContentDelegate>

@property(nonatomic, strong) GADRewardedAd *rewardedAd;

@end

@implementation ViewController
- (void)loadRewardedAd {
  GAMRequest *request = [GAMRequest request];
  [GADRewardedAd
      loadWithAdUnitID:@"ca-app-pub-3940256099942544/4806952744"
                request:request
      completionHandler:^(GADRewardedAd *ad, NSError *error) {
        if (error) {
          NSLog(@"Rewarded ad failed to load with error: %@", [error localizedDescription]);
          return;
        }
        self.rewardedAd = ad;
        NSLog(@"Rewarded ad loaded.");
        self.rewardedAd.fullScreenContentDelegate = self;
      }];
}

/// Tells the delegate that the ad failed to present full screen content.
- (void)ad:(nonnull id<GADFullScreenPresentingAd>)ad
    didFailToPresentFullScreenContentWithError:(nonnull NSError *)error {
    NSLog(@"Ad did fail to present full screen content.");
}

/// Tells the delegate that the ad will present full screen content.
- (void)adWillPresentFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
    NSLog(@"Ad will present full screen content.");
}

/// Tells the delegate that the ad dismissed full screen content.
- (void)adDidDismissFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
    NSLog(@"Ad did dismiss full screen content.");
}

GADRewardedAd는 일회용 객체입니다. 즉, 보상형 광고가 다시 표시할 수 없습니다. 다른 보상형 광고를 로드하는 것이 좋습니다. GADFullScreenContentDelegateadDidDismissFullScreenContent: 메서드에서 이전 보상형 광고가 로드되는 즉시 다음 보상형 광고가 닫았습니다.

광고 표시 및 리워드 이벤트 처리

보상형 광고를 사용자에게 표시하기 전에 사용자에게 보상을 받는 대가로 보상형 광고 콘텐츠를 볼 것인지를 명확하게 선택할 수 있습니다. 보상형 광고 광고는 항상 선택 옵션을 제공해야 합니다.

광고를 표시할 때 GADUserDidEarnRewardHandler 객체를 제공해야 합니다. 사용자의 보상을 처리합니다.

다음 코드는 보상형 광고를 게재하기 위한 최적의 메서드를 나타냅니다.

Swift

func show() {
  guard let rewardedAd = rewardedAd else {
    return print("Ad wasn't ready.")
  }

  // The UIViewController parameter is an optional.
  ad.present(fromRootViewController: nil) {
    let reward = ad.adReward
    print("Reward received with currency \(reward.amount), amount \(reward.amount.doubleValue)")
    // TODO: Reward the user.
  }
}

Objective-C

- (void)show {
  if (self.rewardedAd) {
    // The UIViewController parameter is nullable.
    [self.rewardedAd presentFromRootViewController:nil
                                  userDidEarnRewardHandler:^{
                                  GADAdReward *reward =
                                      self.rewardedAd.adReward;
                                  // TODO: Reward the user!
                                }];
  } else {
    NSLog(@"Ad wasn't ready");
  }
}

FAQ

GADRewardedAd의 리워드 세부정보를 확인할 수 있나요?
예, userDidEarnReward 콜백 전에 보상 금액을 받아야 하는 경우 이(가) 실행되면 GADRewardedAdadReward 속성을 사용하여 광고가 로드된 후 리워드 금액을 확인할 수 있습니다.
초기화 호출에 제한 시간이 있나요?
10초 후에 Google 모바일 광고 SDK가 GADInitializationCompletionHandler에 제공된 startWithCompletionHandler: 메서드를 사용해야 합니다. 확인할 수 있습니다
초기화 콜백을 받을 때 일부 미디에이션 네트워크가 준비되지 않은 경우 어떻게 해야 하나요?

Google 게시자 태그를 사용하여 GADInitializationCompletionHandler 미디에이션 네트워크가 준비되지 않은 경우에도 Google 모바일 광고 SDK는 여전히 해당 네트워크에 광고를 요청합니다. 만약 미디에이션 네트워크가 제한 시간 후에 초기화를 완료하더라도 향후 광고 요청에 사용될 수 있습니다.

이 과정에서 모든 어댑터의 초기화 상태를 앱 세션을 시작할 수 있습니다.GADMobileAds.initializationStatus

특정 미디에이션 네트워크가 준비되지 않은 이유를 확인하려면 어떻게 해야 하나요?

GADAdapterStatus 객체의 description 속성은 어댑터는 광고 요청을 처리할 준비가 되지 않았습니다.

userDidEarnRewardHandler 완료 핸들러가 항상 adDidDismissFullScreenContent: 대리자 메서드보다 먼저 호출되나요?

Google 광고의 경우 userDidEarnRewardHandler 호출이 모두 발생함 (adDidDismissFullScreenContent: 이전) 다음을 통해 게재된 광고 미디에이션은 서드 파티 광고 네트워크를 통해 SDK의 구현에 따라 콜백 순서가 결정됩니다. 광고 네트워크 SDK의 경우 리워드 정보가 포함된 단일 대리자 메서드 제공, 미디에이션 어댑터 adDidDismissFullScreenContent: 전에 userDidEarnRewardHandler를 호출합니다.

GitHub의 예

다음 단계

사용자 개인 정보 보호에 대해 자세히 알아보기