보상형

플랫폼 선택: Android iOS Unity Flutter

보상형 광고는 사용자에게 상호작용에 대한 대가로 인앱 보상을 제공하는 광고입니다. 이 가이드에서는 AdMob의 보상형 광고를 Flutter 앱에 통합하는 방법을 설명합니다.

항상 테스트 광고로 테스트

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

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

Android

ca-app-pub-3940256099942544/5224354917

iOS

ca-app-pub-3940256099942544/1712485313

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

광고 로드

다음 예에서는 보상형 광고를 로드합니다.

RewardedAd.load(
  adUnitId: "_adUnitId",
  request: const AdRequest(),
  rewardedAdLoadCallback: RewardedAdLoadCallback(
    onAdLoaded: (RewardedAd ad) {
      // Called when an ad is successfully received.
      debugPrint('Ad was loaded.');
      // Keep a reference to the ad so you can show it later.
      _rewardedAd = ad;
    },
    onAdFailedToLoad: (LoadAdError error) {
      // Called when an ad request failed.
      debugPrint('Ad failed to load with error: $error');
    },
  ),
);

_adUnitId를 실제로 사용할 광고 단위 ID로 바꿉니다.

보상형 광고 이벤트

FullScreenContentCallback을 사용하면 광고 게재, 광고 닫기와 같은 수명 주기 이벤트를 수신 대기할 수 있습니다. 이러한 이벤트에 대한 알림을 받으려면 광고를 게재하기 전에 RewardedAd.fullScreenContentCallback을 설정하세요. 이 예에서는 각 메서드를 구현하고 콘솔에 메시지를 기록합니다.

ad.fullScreenContentCallback = FullScreenContentCallback(
  onAdShowedFullScreenContent: (ad) {
    // Called when the ad showed the full screen content.
    debugPrint('Ad showed full screen content.');
  },
  onAdFailedToShowFullScreenContent: (ad, err) {
    // Called when the ad failed to show full screen content.
    debugPrint('Ad failed to show full screen content with error: $err');
    // Dispose the ad here to free resources.
    ad.dispose();
  },
  onAdDismissedFullScreenContent: (ad) {
    // Called when the ad dismissed full screen content.
    debugPrint('Ad was dismissed.');
    // Dispose the ad here to free resources.
    ad.dispose();
  },
  onAdImpression: (ad) {
    // Called when an impression occurs on the ad.
    debugPrint('Ad recorded an impression.');
  },
  onAdClicked: (ad) {
    // Called when a click is recorded for an ad.
    debugPrint('Ad was clicked.');
  },
);

디스플레이 광고

RewardedAd는 모든 앱 콘텐츠 위에 오버레이로 표시되며 정적으로 배치되므로 Flutter 위젯 트리에 추가할 수 없습니다. show()를 호출하여 광고 게재 시점을 선택할 수 있습니다. RewardedAd.show()는 사용자가 보상을 획득할 때 호출되는 OnUserEarnedRewardCallback을 사용합니다. 이 이벤트를 구현하고 사용자에게 광고 시청에 대한 보상을 제공해야 합니다.

_rewardedAd?.show(
  onUserEarnedReward:
      (AdWithoutView ad, RewardItem rewardItem) {
        debugPrint(
          'Reward amount: ${rewardItem.amount}',
        );
      },
);

show()가 호출되면 이 방식으로 게재된 Ad는 프로그래매틱 방식으로 삭제할 수 없으며 사용자가 입력해야 삭제할 수 있습니다. RewardedAd는 한 번만 게재될 수 있습니다. 이후 표시되는 호출에서 onAdFailedToShowFullScreenContent를 트리거합니다.

광고에 대한 액세스가 더 이상 필요하지 않으면 광고를 삭제해야 합니다. dispose()를 호출하기 가장 좋은 시점은 FullScreenContentCallback.onAdDismissedFullScreenContentFullScreenContentCallback.onAdFailedToShowFullScreenContent 콜백이 실행될 때입니다.

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

서버 측 확인 콜백에서 추가 데이터가 필요한 앱은 보상형 광고의 맞춤 데이터 기능을 사용해야 합니다. 보상형 광고 객체에 설정된 모든 문자열 값은 SSV 콜백의 custom_data 쿼리 매개변수에 전달됩니다. 맞춤 데이터 값이 설정되지 않은 경우 custom_data 쿼리 매개변수 값은 SSV 콜백에 표시되지 않습니다.

다음 코드 샘플은 보상형 광고가 로드된 후 SSV 옵션을 설정하는 방법을 보여줍니다.

RewardedAd.load(
  adUnitId: "_adUnitId",
  request: AdRequest(),
  rewardedAdLoadCallback: RewardedAdLoadCallback(
    onAdLoaded: (ad) {
      ServerSideVerificationOptions _options =
          ServerSideVerificationOptions(
              customData: 'SAMPLE_CUSTOM_DATA_STRING');
      ad.setServerSideOptions(_options);
      _rewardedAd = ad;
    },
    onAdFailedToLoad: (error) {},
  ),
);

SAMPLE_CUSTOM_DATA_STRING을 맞춤 데이터로 바꿉니다.

GitHub의 전체 예

보상형 광고