앱 오프닝 광고

플랫폼 선택: Android iOS Unity Flutter

이 가이드는 앱 오프닝 광고를 통합하려는 게시자를 대상으로 작성되었습니다.

앱 오프닝 광고는 앱 로드 화면에서 수익을 올리려는 게시자를 위해 개발된 특별한 광고 형식입니다. 앱 오프닝 광고는 사용자가 언제든지 닫을 수 있습니다. 사용자가 앱을 포그라운드로 가져올 때 앱 오프닝 광고가 표시될 수 있습니다.

앱 오프닝 광고는 사용자가 앱을 사용 중임을 알 수 있도록 작은 브랜딩 영역을 자동으로 표시합니다. 앱 오프닝 광고는 다음과 같이 게재됩니다.

앱 오프닝 광고를 구현하는 데 필요한 단계는 크게 다음과 같이 나눌 수 있습니다.

  1. 게재하려는 광고를 로드하는 관리자 클래스를 생성합니다.
  2. 앱 포그라운드 이벤트 중에 광고를 표시합니다.
  3. 프레젠테이션 콜백을 처리합니다.

기본 요건

항상 테스트 광고로 테스트

앱을 제작하고 테스트할 때는 운영 중인 실제 광고 대신 테스트 광고를 사용하세요. 이렇게 하지 않으면 계정이 정지될 수 있습니다.

테스트 광고를 로드하는 가장 쉬운 방법은 앱 오프닝 광고 전용 테스트 광고 단위 ID를 사용하는 것입니다.

ca-app-pub-3940256099942544/5575463023

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

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

관리자 클래스 구현

광고는 빠르게 게재되어야 하므로 광고를 게재하기 전에 미리 로드하는 것이 좋습니다. 이렇게 하면 사용자가 앱을 실행하자마자 바로 광고를 게재할 수 있습니다. 광고를 표시해야 하는 시점에 앞서 미리 광고 요청을 할 수 있도록 관리자 클래스를 구현합니다.

AppOpenAdManager라는 새 싱글톤 클래스를 만듭니다.

Swift

class AppOpenAdManager: NSObject {
  /// The app open ad.
  var appOpenAd: AppOpenAd?
  /// Maintains a reference to the delegate.
  weak var appOpenAdManagerDelegate: AppOpenAdManagerDelegate?
  /// Keeps track of if an app open ad is loading.
  var isLoadingAd = false
  /// Keeps track of if an app open ad is showing.
  var isShowingAd = false
  /// Keeps track of the time when an app open ad was loaded to discard expired ad.
  var loadTime: Date?
  /// For more interval details, see https://support.google.com/admob/answer/9341964
  let timeoutInterval: TimeInterval = 4 * 3_600

  static let shared = AppOpenAdManager()

Objective-C

@interface AppOpenAdManager ()

/// The app open ad.
@property(nonatomic, strong, nullable) GADAppOpenAd *appOpenAd;
/// Keeps track of if an app open ad is loading.
@property(nonatomic, assign) BOOL isLoadingAd;
/// Keeps track of if an app open ad is showing.
@property(nonatomic, assign) BOOL isShowingAd;
/// Keeps track of the time when an app open ad was loaded to discard expired ad.
@property(nonatomic, strong, nullable) NSDate *loadTime;

@end

/// For more interval details, see https://support.google.com/admob/answer/9341964
static const NSInteger kTimeoutInterval = 4;

@implementation AppOpenAdManager

+ (nonnull AppOpenAdManager *)sharedInstance {
  static AppOpenAdManager *instance = nil;
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    instance = [[AppOpenAdManager alloc] init];
  });
  return instance;
}

AppOpenAdManagerDelegate 프로토콜을 구현합니다.

Swift

protocol AppOpenAdManagerDelegate: AnyObject {
  /// Method to be invoked when an app open ad life cycle is complete (i.e. dismissed or fails to
  /// show).
  func appOpenAdManagerAdDidComplete(_ appOpenAdManager: AppOpenAdManager)
}

Objective-C

@protocol AppOpenAdManagerDelegate <NSObject>
/// Method to be invoked when an app open ad life cycle is complete (i.e. dismissed or fails to
/// show).
- (void)adDidComplete;
@end

광고 로드

다음 단계는 앱 오프닝 광고를 로드하는 것입니다.

Swift

func loadAd() async {
  // Do not load ad if there is an unused ad or one is already loading.
  if isLoadingAd || isAdAvailable() {
    return
  }
  isLoadingAd = true

  do {
    appOpenAd = try await AppOpenAd.load(
      with: "ca-app-pub-3940256099942544/5575463023", request: Request())
    appOpenAd?.fullScreenContentDelegate = self
    loadTime = Date()
  } catch {
    print("App open ad failed to load with error: \(error.localizedDescription)")
    appOpenAd = nil
    loadTime = nil
  }
  isLoadingAd = false
}

Objective-C

- (void)loadAd {
  // Do not load ad if there is an unused ad or one is already loading.
  if ([self isAdAvailable] || self.isLoadingAd) {
    return;
  }
  self.isLoadingAd = YES;

  [GADAppOpenAd loadWithAdUnitID:@"ca-app-pub-3940256099942544/5575463023"
                         request:[GADRequest request]
               completionHandler:^(GADAppOpenAd * _Nullable appOpenAd, NSError * _Nullable error) {
    self.isLoadingAd = NO;
    if (error) {
      NSLog(@"App open ad failed to load with error: %@", error);
      self.appOpenAd = nil;
      self.loadTime = nil;
      return;
    }
    self.appOpenAd = appOpenAd;
    self.appOpenAd.fullScreenContentDelegate = self;
    self.loadTime = [NSDate date];
  }];
}

광고 표시

다음 단계는 앱 오프닝 광고를 표시하는 것입니다. 사용할 수 있는 광고가 없으면 새 광고를 로드하려고 시도합니다.

Swift

func showAdIfAvailable() {
  // If the app open ad is already showing, do not show the ad again.
  if isShowingAd {
    return print("App open ad is already showing.")
  }

  // If the app open ad is not available yet but is supposed to show, load
  // a new ad.
  if !isAdAvailable() {
    print("App open ad is not ready yet.")
    // The app open ad is considered to be complete in this example.
    appOpenAdManagerDelegate?.appOpenAdManagerAdDidComplete(self)
    // Load a new ad.
    return
  }

  if let appOpenAd {
    appOpenAd.present(from: nil)
    isShowingAd = true
  }
}

Objective-C

- (void)showAdIfAvailable {
  // If the app open ad is already showing, do not show the ad again.
  if (self.isShowingAd) {
    NSLog(@"App open ad is already showing.");
    return;
  }

  // If the app open ad is not available yet but is supposed to show, load
  // a new ad.
  if (![self isAdAvailable]) {
    NSLog(@"App open ad is not ready yet.");
    // The app open ad is considered to be complete in this example.
    [self adDidComplete];
    // Load a new ad.
    return;
  }

  [self.appOpenAd presentFromRootViewController:nil];
  self.isShowingAd = YES;
}

앱 포그라운드 이벤트 중에 광고 표시

애플리케이션이 활성화되면 showAdIfAvailable()를 호출하여 광고가 있는 경우 광고를 표시하거나 새 광고를 로드합니다.

Swift

func applicationDidBecomeActive(_ application: UIApplication) {
  // Show the app open ad when the app is foregrounded.
  AppOpenAdManager.shared.showAdIfAvailable()
}

Objective-C

- (void) applicationDidBecomeActive:(UIApplication *)application {
  // Show the app open ad when the app is foregrounded.
  [AppOpenAdManager.sharedInstance showAdIfAvailable];
}

프레젠테이션 콜백 처리

표시 이벤트 알림을 받으려면 반환된 광고의 fullScreenContentDelegate 속성에 GADFullScreenContentDelegate를 할당해야 합니다.

Swift

appOpenAd?.fullScreenContentDelegate = self

Objective-C

self.appOpenAd.fullScreenContentDelegate = self;

특히 첫 번째 광고 표시가 완료되면 다음 앱 오프닝 광고를 요청해야 합니다. 다음 코드는 AppOpenAdManager 파일에서 프로토콜을 구현하는 방법을 보여줍니다.

Swift

func adDidRecordImpression(_ ad: FullScreenPresentingAd) {
  print("App open ad recorded an impression.")
}

func adDidRecordClick(_ ad: FullScreenPresentingAd) {
  print("App open ad recorded a click.")
}

func adWillDismissFullScreenContent(_ ad: FullScreenPresentingAd) {
  print("App open ad will be dismissed.")
}

func adWillPresentFullScreenContent(_ ad: FullScreenPresentingAd) {
  print("App open ad will be presented.")
}

func adDidDismissFullScreenContent(_ ad: FullScreenPresentingAd) {
  print("App open ad was dismissed.")
  appOpenAd = nil
  isShowingAd = false
  appOpenAdManagerDelegate?.appOpenAdManagerAdDidComplete(self)
  Task {
    await loadAd()
  }
}

func ad(
  _ ad: FullScreenPresentingAd,
  didFailToPresentFullScreenContentWithError error: Error
) {
  print("App open ad failed to present with error: \(error.localizedDescription)")
  appOpenAd = nil
  isShowingAd = false
  appOpenAdManagerDelegate?.appOpenAdManagerAdDidComplete(self)
  Task {
    await loadAd()
  }
}

Objective-C

- (void)adDidRecordImpression:(nonnull id<GADFullScreenPresentingAd>)ad {
  NSLog(@"App open ad recorded an impression.");
}

- (void)adDidRecordClick:(nonnull id<GADFullScreenPresentingAd>)ad {
  NSLog(@"App open ad recorded a click.");
}

- (void)adWillPresentFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
  NSLog(@"App open ad will be presented.");
}

- (void)adWillDismissFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
  NSLog(@"App open ad will be dismissed.");
}

- (void)adDidDismissFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
  NSLog(@"App open ad was dismissed.");
  self.appOpenAd = nil;
  self.isShowingAd = NO;
  [self adDidComplete];
  [self loadAd];
}

- (void)ad:(nonnull id<GADFullScreenPresentingAd>)ad
    didFailToPresentFullScreenContentWithError:(nonnull NSError *)error {
  NSLog(@"App open ad failed to present with error: %@", error.localizedDescription);
  self.appOpenAd = nil;
  self.isShowingAd = NO;
  [self adDidComplete];
  [self loadAd];
}

광고 만료 고려

만료된 광고가 표시되지 않도록 하려면 광고 참조가 로드된 후 경과 시간을 확인하는 메서드를 앱 대리자에 추가하면 됩니다.

AppOpenAdManager에서 loadTime라는 Date 속성을 추가하고 광고가 로드될 때 속성을 설정합니다. 광고가 로드된 후 아직 일정 시간이 경과하지 않았으면 true를 반환하는 메서드를 추가할 수 있습니다. 광고를 표시하기 전에 광고 참조의 유효성을 확인해야 합니다.

Swift

private func wasLoadTimeLessThanNHoursAgo(timeoutInterval: TimeInterval) -> Bool {
  // Check if ad was loaded more than n hours ago.
  if let loadTime = loadTime {
    return Date().timeIntervalSince(loadTime) < timeoutInterval
  }
  return false
}

private func isAdAvailable() -> Bool {
  // Check if ad exists and can be shown.
  return appOpenAd != nil && wasLoadTimeLessThanNHoursAgo(timeoutInterval: timeoutInterval)
}

Objective-C

- (BOOL)wasLoadTimeLessThanNHoursAgo:(int)n {
  // Check if ad was loaded more than n hours ago.
  NSDate *now = [NSDate date];
  NSTimeInterval timeIntervalBetweenNowAndLoadTime = [now timeIntervalSinceDate:self.loadTime];
  double secondsPerHour = 3600.0;
  double intervalInHours = timeIntervalBetweenNowAndLoadTime / secondsPerHour;
  return intervalInHours < n;
}

- (BOOL)isAdAvailable {
  // Check if ad exists and can be shown.
  return _appOpenAd && [self wasLoadTimeLessThanNHoursAgo:kTimeoutInterval];
}

콜드 스타트 및 로드 화면

이 문서에서는 메모리에 일시중지된 상태로 있는 앱을 사용자가 포그라운드로 가져올 때만 앱 오프닝 광고가 게재된다고 가정합니다. '콜드 스타트'는 앱이 실행되었지만 실행되기 전에 앱이 일시중지 상태로 메모리에 있지 않은 경우 발생합니다.

콜드 스타트의 한 예는 사용자가 앱을 처음으로 열 때입니다. 콜드 스타트 상황에는 즉시 표시할 수 있도록 미리 로드해둔 앱 오프닝 광고가 없습니다. 광고를 요청하고 광고를 수신하는 시점 사이에 지연 시간이 발생하면 사용자가 그 잠깐 동안 앱을 사용하다가 갑작스럽게 광고가 게재되며 불편을 겪을 수 있습니다. 이는 사용자 경험에 악영향을 미치므로 피해야 합니다.

콜드 스타트가 발생할 때 앱 오프닝 광고를 사용하는 바람직한 방법은 게임 또는 앱 애셋을 로드하기 위한 로드 화면을 사용하고 해당 로드 화면에만 광고를 표시하는 것입니다. 앱에서 로드가 완료되고 사용자에게 앱의 주요 콘텐츠가 표시된 후에는 광고가 게재되지 않아야 합니다.

권장사항

Google에서는 앱 로드 화면을 통해 수익을 창출할 수 있도록 앱 오프닝 광고를 만들었지만, 사용자가 앱을 사용하는 데 불편하지 않도록 권장사항을 고려하는 것이 중요합니다. 이러한 권장사항은 다음과 같습니다.

  • 사용자가 앱을 몇 번 사용했을 때까지 기다린 후에 첫 앱 오프닝 광고를 표시합니다.
  • 사용자가 앱이 로드되기를 기다리는 동안 앱 오프닝 광고를 표시합니다.
  • 앱 오프닝 광고 아래에 로드 화면이 있고 사용자가 광고를 닫기 전에 화면 로드가 완료되면 adDidDismissFullScreenContent 메서드로 로드 화면을 닫는 것이 좋습니다.

GitHub의 전체 예

Swift Objective-C

다음 단계

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