삽입형

전면 광고는 호스트 앱의 인터페이스를 가리는 전체 화면 광고입니다. 일반적으로 활동이 바뀌는 시점 또는 게임에서 다음 레벨로 넘어갈 때처럼 앱 이용이 잠시 중단될 때 자연스럽게 광고가 게재됩니다. 앱에서 전면 광고가 표시될 때 사용자는 광고를 탭하여 대상으로 이동하거나 광고를 닫고 앱으로 돌아갈 수도 있습니다

이 가이드에서는 전면 광고를 Flutter 앱에 통합하는 방법을 설명합니다.

항상 테스트 광고로 테스트

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

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

Android

ca-app-pub-3940256099942544/1033173712

iOS

ca-app-pub-3940256099942544/4411468910

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

광고 로드

다음 예에서는 전면 광고를 로드합니다.

class InterstitialExampleState extends State<InterstitialExample> {
  InterstitialAd? _interstitialAd;

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = Platform.isAndroid
    ? 'ca-app-pub-3940256099942544/1033173712'
    : 'ca-app-pub-3940256099942544/4411468910';

  /// Loads an interstitial ad.
  void loadAd() {
    InterstitialAd.load(
        adUnitId: adUnitId,
        request: const AdRequest(),
        adLoadCallback: InterstitialAdLoadCallback(
          // Called when an ad is successfully received.
          onAdLoaded: (ad) {
            debugPrint('$ad loaded.');
            // Keep a reference to the ad so you can show it later.
            _interstitialAd = ad;
          },
          // Called when an ad request failed.
          onAdFailedToLoad: (LoadAdError error) {
            debugPrint('InterstitialAd failed to load: $error');
          },
        ));
  }
}

전면 광고 이벤트

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

class InterstitialExampleState extends State<InterstitialExample> {
  InterstitialAd? _interstitialAd;

  // TODO: replace this test ad unit with your own ad unit.
  final adUnitId = Platform.isAndroid
    ? 'ca-app-pub-3940256099942544/1033173712'
    : 'ca-app-pub-3940256099942544/4411468910';

  /// Loads an interstitial ad.
  void loadAd() {
    InterstitialAd.load(
        adUnitId: adUnitId,
        request: const AdRequest(),
        adLoadCallback: InterstitialAdLoadCallback(
          // Called when an ad is successfully received.
          onAdLoaded: (ad) {
             ad.fullScreenContentCallback = FullScreenContentCallback(
                // Called when the ad showed the full screen content.
                onAdShowedFullScreenContent: (ad) {},
                // Called when an impression occurs on the ad.
                onAdImpression: (ad) {},
                // Called when the ad failed to show full screen content.
                onAdFailedToShowFullScreenContent: (ad, err) {
                  // Dispose the ad here to free resources.
                  ad.dispose();
                },
                // Called when the ad dismissed full screen content.
                onAdDismissedFullScreenContent: (ad) {
                  // Dispose the ad here to free resources.
                  ad.dispose();
                },
                // Called when a click is recorded for an ad.
                onAdClicked: (ad) {});

            debugPrint('$ad loaded.');
            // Keep a reference to the ad so you can show it later.
            _interstitialAd = ad;
          },
          // Called when an ad request failed.
          onAdFailedToLoad: (LoadAdError error) {
            debugPrint('InterstitialAd failed to load: $error');
          },
        ));
  }
}

전면 광고 표시

InterstitialAd는 모든 앱 콘텐츠 위에 Overlay로 표시되고 정적으로 배치됩니다. 따라서 Flutter 위젯 트리에 추가할 수 없습니다. show()를 호출하여 광고 게재 시점을 선택할 수 있습니다.

_interstitiaAd.show();

show()가 호출되면 이 방식으로 표시된 Ad는 프로그래매틱 방식으로 닫을 수 없으며 사용자 입력이 필요합니다. InterstitialAd는 한 번만 표시할 수 있습니다. 이후에 표시할 호출은 onAdFailedToShowFullScreenContent을 트리거합니다.

더 이상 액세스할 필요가 없는 광고는 폐기해야 합니다. dispose()를 호출하기 가장 좋은 시점은 FullScreenContentCallback.onAdDismissedFullScreenContentFullScreenContentCallback.onAdFailedToShowFullScreenContent 콜백에서 실행하는 것입니다.

이제 완료됐습니다. 이제 앱에서 전면 광고를 표시할 수 있습니다.

다음 단계

GitHub의 전체 예

전면 광고