보상형 전면 광고 (베타)

보상형 전면 광고는 보상이 제공되는 인센티브형 광고 형식의 강점입니다. 자연스러운 앱 전환 중에 자동으로 맞춤설정할 수 있습니다 보상형 광고와 달리 사용자는 선택해야 합니다.

기본 요건

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

구현

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

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

광고 로드

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

Swift

import GoogleMobileAds
import UIKit

class ViewController: UIViewController {

  private var rewardedInterstitialAd: GADRewardedInterstitialAd?

  override func viewDidLoad() {
    super.viewDidLoad()

    do {
      rewardedInterstitialAd = try await GADRewardedInterstitialAd.load(
        withAdUnitID: "/21775744923/example/rewarded_interstitial", request: GAMRequest())
    } catch {
      print("Failed to load rewarded interstitial ad with error: \(error.localizedDescription)")
    }
  }
}

Objective-C

#import "ViewController.h"

@interface ViewController ()
@property(nonatomic, strong) GADRewardedInterstitialAd* rewardedInterstitialAd;
@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];

  [GADRewardedInterstitialAd
      loadWithAdUnitID:@"<var label='the ad unit ID'>/21775744923/example/rewarded_interstitial</var>"
                request:[GAMRequest request]
      completionHandler:^(
          GADRewardedInterstitialAd* _Nullable rewardedInterstitialAd,
          NSError* _Nullable error) {
        if (!error) {
          self.rewardedInterstitialAd = rewardedInterstitialAd;
        }
      }
  ];
}

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

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

다음 코드 샘플은 보상형 광고에 맞춤 데이터를 설정하는 방법을 보여줍니다. 삽입 광고 개체를 1개 이상 만들어야 합니다.

Swift

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

Objective-C

[GADRewardedInterstitialAd
    loadWithAdUnitID:@"/21775744923/example/rewarded_interstitial"
              request:GAMRequest
    completionHandler:^(GADRewardedInterstitialAd *ad, NSError *error) {
      if (error) {
        // Handle Error
        return;
      }
      self.rewardedInterstitialAd = 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 rewardedInterstitialAd: GADRewardedInterstitialAd?

  override func viewDidLoad() {
    super.viewDidLoad()

    do {
      rewardedInterstitialAd = try await GADRewardedInterstitialAd.load(
        withAdUnitID: "/21775744923/example/rewarded_interstitial", request: GAMRequest())
      self.rewardedInterstitialAd?.fullScreenContentDelegate = self
    } catch {
      print("Failed to load rewarded interstitial ad 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) GADRewardedInterstitialAd *rewardedInterstitialAd;
@end

@implementation ViewController

- (void)viewDidLoad {
  [super viewDidLoad];
  // Do any additional setup after loading the view.

  [GADRewardedInterstitialAd
      loadWithAdUnitID:@"/21775744923/example/rewarded_interstitial"
                request:[GAMRequest request]
      completionHandler:^(
          GADRewardedInterstitialAd *_Nullable rewardedInterstitialAd,
          NSError *_Nullable error) {
        if (!error) {
          self.rewardedInterstitialAd = rewardedInterstitialAd;
          self.rewardedInterstitialAd.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.");
}

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

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

다음 코드는 보상형 광고를 게재하는 데 가장 적합한 메서드를 나타냅니다. 전면 광고

Swift

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

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

Objective-C

- (void)show {
  // The UIViewController parameter is nullable.
  [_rewardedInterstitialAd presentFromRootViewController:nil
                                userDidEarnRewardHandler:^{

                                  GADAdReward *reward =
                                      self.rewardedInterstitialAd.adReward;
                                  // TODO: Reward the user.
                                }];
}

다음 단계

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