앱 오프닝 광고

이 가이드는 앱 오프닝 광고를 통합하는 게시자를 위해 작성되었습니다.

앱 오프닝 광고는 수익을 창출하려는 게시자를 위한 특수한 광고 형식입니다. 확인할 수 있습니다. 앱 오프닝 광고는 사용자가 언제든지 닫을 수 있습니다. 앱 오프닝 광고는 사용자가 앱을 포그라운드로 가져올 때 표시될 수 있습니다.

앱 오프닝 광고에는 작은 브랜딩 영역이 자동으로 표시되므로 사용자가 어디에 있는지 알 수 있습니다. 있습니다. 다음은 앱 오프닝 광고의 예입니다.

앱 오프닝 광고를 구현하는 데 필요한 단계는 대략적으로 다음과 같습니다.

  1. 광고를 표시하기 전에 로드하는 관리자 클래스를 만듭니다.
  2. 앱 포그라운드 이벤트 중 추가를 표시합니다.
  3. 프레젠테이션 콜백을 처리합니다.

기본 요건

항상 테스트 광고로 테스트

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

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

ca-app-pub-3940256099942544/5575463023

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

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

관리자 클래스 구현

광고가 빠르게 게재되어야 하므로 로드 전에 광고를 로드하는 것이 좋습니다. 표시합니다. 이렇게 하면 사용자가 접속하자마자 바로 광고를 시작할 수 있습니다. 있습니다. 필요할 때 미리 광고를 요청할 수 있도록 관리자 클래스 구현 입니다.

AppOpenAdManager라는 새 싱글톤 클래스를 만들고 다음과 같이 작성합니다. 다음과 같습니다.

Swift

class AppOpenAdManager: NSObject {
  var appOpenAd: GADAppOpenAd?
  var isLoadingAd = false.
  var isShowingAd = false

  static let shared = AppOpenAdManager()

  private func loadAd() async {
    // TODO: Implement loading an ad.
  }

  func showAdIfAvailable() {
    // TODO: Implement showing an ad.
  }

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

Objective-C

@interface AppOpenAdManager ()
@property(nonatomic, strong) GADAppOpenAd *appOpenAd;
@property(nonatomic, assign) BOOL isLoadingAd;
@property(nonatomic, assign) BOOL isShowingAd;

@end

@implementation AppOpenAdManager

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

- (void)loadAd {
  // TODO: Implement loading an ad.
}

// Add this method to the .h file.
- (void)showAdIfAvailable {
  // TODO: Implement showing an ad.
}

- (BOOL)isAdAvailable {
  // Check if ad exists and can be shown.
  return self.appOpenAd != nil;
}

@end

광고 로드

다음 단계는 loadAd() 메서드를 작성하는 것입니다.

Swift

private 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 GADAppOpenAd.load(
      withAdUnitID: "ca-app-pub-3940256099942544/5575463023", request: GADRequest())
  } catch {
    print("App open ad failed to load with error: \(error.localizedDescription)")
  }
  isLoadingAd = false
}

Objective-C

- (void)loadAd {
  // Do not load ad if there is an unused ad or one is already loading.
  if (self.isLoadingAd || [self isAdAvailable]) {
    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(@"Failed to load app open ad: %@", error);
                 return;
               }
               self.appOpenAd = appOpenAd;
             }];
}

광고 게재

다음 단계는 showAdIfAvailable() 메서드를 작성하는 것입니다. 광고가 사용할 수 있으면 메서드는 광고를 로드하려고 시도합니다.

Swift

func showAdIfAvailable() {
  // If the app open ad is already showing, do not show the ad again.
  guard !isShowingAd else { return }

  // If the app open ad is not available yet but is supposed to show, load
  // a new ad.
  if !isAdAvailable() {
    Task {
      await loadAd()
    }
    return
  }

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

Objective-C

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

  // If the app open ad is not available yet but is supposed to show, load a
  // new ad.
  if (![self isAdAvailable]) {
    [self loadAd];
    return;
  }

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

앱 포그라운드 이벤트 중에 광고 게재

애플리케이션이 활성화되면 showAdIfAvailable()를 호출하여 다음과 같은 경우 광고를 표시합니다. 사용할 수 있거나 새 리소스를 로드합니다.

Swift

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
  // ...

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

Objective-C

@implementation AppDelegate
// ...

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

@end

프레젠테이션 콜백 처리

앱에서 앱 오프닝 광고를 표시할 때는 GADFullScreenContentDelegate: 특정 프레젠테이션 이벤트를 처리합니다. 포함 특히 첫 번째 앱 오프닝 광고가 게재되면 표시됩니다.

AppOpenAdManager 클래스에서 다음을 추가합니다.

Swift

class AppOpenAdManager: NSObject, GADFullScreenContentDelegate {
  // ...

  private 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 GADAppOpenAd.load(
        withAdUnitID: "ca-app-pub-3940256099942544/5575463023", request: GADRequest())
      appOpenAd?.fullScreenContentDelegate = self
    } catch {
      print("App open ad failed to load with error: \(error.localizedDescription)")
    }
    isLoadingAd = false
  }

  // ...

  // MARK: - GADFullScreenContentDelegate methods

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

  func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    appOpenAd = nil
    isShowingAd = false
    // Reload an ad.
    Task {
      await loadAd()
    }
  }

  func ad(
    _ ad: GADFullScreenPresentingAd,
    didFailToPresentFullScreenContentWithError error: Error
  ) {
    appOpenAd = nil
    isShowingAd = false
    // Reload an ad.
    Task {
      await loadAd()
    }
  }
}

Objective-C

@interface AppOpenAdManager () <GADFullScreenContentDelegate>
@property(nonatomic, strong) GADAppOpenAd *appOpenAd
@property(nonatomic, assign) BOOL isLoadingAd;
@property(nonatomic, assign) BOOL isShowingAd;

@end

@implementation AppOpenAdManager

// ...

- (void)loadAd {
  // Do not load ad if there is an unused ad or one is already loading.
  if (self.isLoadingAd || [self isAdAvailable]) {
    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(@"Failed to load app open ad: %@", error);
                 return;
               }
               self.appOpenAd = appOpenAd;
               self.appOpenAd.fullScreenContentDelegate = self;
             }];
}

- (BOOL)isAdAvailable {
  // Check if ad exists and can be shown.
  return self.appOpenAd != nil;
}

// ...

#pragma mark - GADFullScreenContentDelegate methods

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

- (void)adDidDismissFullScreenContent:(nonnull id<GADFullScreenPresentingAd>)ad {
  self.appOpenAd = nil;
  self.isShowingAd = NO;
  // Reload an ad.
  [self loadAd];
}

- (void)ad:(nonnull id<GADFullScreenPresentingAd>)ad
    didFailToPresentFullScreenContentWithError:(nonnull NSError *)error {
  self.appOpenAd = nil;
  self.isShowingAd = NO;
  // Reload an ad.
  [self loadAd];
}

@end

광고 만료 고려

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

AppOpenAdManager에서 loadTime라는 Date 속성을 추가하고 속성을 사용할 수 있습니다. 그런 다음 다음과 같은 경우 true를 반환하는 메서드를 추가할 수 있습니다. 광고가 로드된 후 특정 시간이 지나지 않은 경우 광고를 게재하기 전에 광고 참조의 유효성을 확인해야 합니다.

Swift

class AppOpenAdManager: NSObject, GADFullScreenContentDelegate {
  var appOpenAd: GADAppOpenAd?
  var isLoadingAd = false.
  var isShowingAd = false
  var loadTime: Date?
  let fourHoursInSeconds = TimeInterval(3600 * 4)

  // ...

  private 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 GADAppOpenAd.load(
        withAdUnitID: "ca-app-pub-3940256099942544/5575463023", request: GADRequest())
      appOpenAd?.fullScreenContentDelegate = self
      loadTime = Date()
    } catch {
      print("App open ad failed to load with error: \(error.localizedDescription)")
    }
    isLoadingAd = false
  }

  private func wasLoadTimeLessThanFourHoursAgo() -> Bool {
    guard let loadTime = loadTime else { return false }
    // Check if ad was loaded more than four hours ago.
    return Date().timeIntervalSince(loadTime) < fourHoursInSeconds
  }

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

Objective-C

static NSTimeInterval const fourHoursInSeconds = 3600 * 4;

@interface AppOpenAdManager () <GADFullScreenContentDelegate>
@property(nonatomic, strong) GADAppOpenAd *appOpenAd
@property(nonatomic, assign) BOOL isLoadingAd;
@property(nonatomic, assign) BOOL isShowingAd;
@property(weak, nonatomic) NSDate *loadTime;

@end

@implementation AppOpenAdManager

// ...

- (void)loadAd {
  // Do not load ad if there is an unused ad or one is already loading.
  if (self.isLoadingAd || [self isAdAvailable]) {
    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(@"Failed to load app open ad: %@", error);
                 return;
               }
               self.appOpenAd = appOpenAd;
               self.appOpenAd.fullScreenContentDelegate = self;
               self.loadTime = [NSDate date];
             }];
}

- (BOOL)wasLoadTimeLessThanFourHoursAgo {
  // Check if ad was loaded more than four hours ago.
  return [[NSDate Date] timeIntervalSinceDate:self.loadTime] < fourHoursInSeconds;
}

- (BOOL)isAdAvailable {
  // Check if ad exists and can be shown.
  return self.appOpenAd != nil && [self wasLoadTimeLessThanFourHoursAgo];
}

@end

콜드 스타트 및 로드 화면

이 문서에서는 사용자가 내 앱을 찾을 때만 앱 오프닝 광고를 게재한다고 가정합니다. 메모리에서 정지된 경우 앱을 포그라운드로 설정하세요. '콜드 스타트' 은(는) 다음과 같은 경우에 발생합니다. 앱이 실행되었지만 이전에 메모리에서 정지되지 않았어야 합니다.

콜드 스타트의 예로는 사용자가 앱을 처음 여는 경우를 들 수 있습니다. 콜드 스타트를 사용하면 이전에 로드한 앱 오프닝 광고가 게재되지 않습니다. 바로 표시되도록 할 수 있습니다. 광고를 요청한 후 광고를 받기까지 걸리는 시간 사용자가 내 앱을 다시 사용하기 전에 잠시 앱을 엉뚱한 광고를 보고 깜짝 놀란 경우 이것은 피해야 하는 부정적인 사용자 경험을 제공할 수 있습니다

콜드 스타트 시 앱 오프닝 광고를 사용하는 좋은 방법은 로드 화면을 사용하는 것입니다. 를 설정하여 게임 또는 앱 애셋을 로드하고 화면 앱 로드가 완료되고 사용자를 기본 광고를 게재하지 않습니다.

권장사항

Google에서는 앱의 로드 화면에서 수익을 창출할 수 있도록 앱 오프닝 광고를 만들었지만 사용자가 Google 모바일 광고 SDK를 즐겁게 사용할 수 있도록 있습니다. 다음 작업을 수행해야 합니다.

  • 사용자가 첫 번째 앱 오프닝 광고를 게재하기 전에 실행할 수도 있습니다
  • 사용자가 기다리지 않을 시간에 앱 오프닝 광고 게재 최대 24시간이 필요합니다.
  • 앱 오프닝 광고 아래에 로드 화면이 있고 로드 화면이 있는 경우 광고가 닫히기 전에 로드가 완료된 경우 adDidDismissFullScreenContent 메서드의 로드 중 화면

GitHub의 전체 예시

Swift Objective-C

다음 단계

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