시작하기

AdMob 미디에이션은 AdMob 네트워크, 서드 파티 광고 소스 등 다양한 소스를 통해 앱에 광고를 한곳에서 게재할 수 있는 기능입니다. AdMob 미디에이션을 이용하면 여러 네트워크에 광고 요청을 전송하여 광고 게재에 최적인 네트워크를 찾을 수 있으므로 유효노출률을 극대화하고 수익을 늘리는 데 도움이 됩니다. 우수사례

기본 요건

광고 형식에 적합한 미디에이션 기능을 통합하기 전에 해당 광고 형식을 앱에 통합해야 합니다.

미디에이션을 처음 사용하는 경우 AdMob 미디에이션 개요를 읽어보세요.

Google 모바일 광고 SDK (베타) 초기화

빠른 시작 가이드에서는 Google 모바일 광고 SDK (베타)를 초기화하는 방법을 보여줍니다. 초기화 호출 중에는 미디에이션 어댑터도 초기화됩니다. 첫 번째 광고 요청에 모든 광고 네트워크가 참여할 수 있도록 하려면 광고를 로드하기 전에 초기화가 완료될 때까지 기다려야 합니다.

다음 샘플 코드에서는 광고 요청을 하기 전에 각 어댑터의 초기화 상태를 확인하는 방법을 보여줍니다.

Kotlin

import com.google.android.libraries.ads.mobile.sdk.MobileAds
import com.google.android.libraries.ads.mobile.sdk.initialization.InitializationConfig
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class MainActivity : AppCompatActivity() {
  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)

    val backgroundScope = CoroutineScope(Dispatchers.IO)
    backgroundScope.launch {
      // Initialize Google Mobile Ads SDK (beta) on a background thread.
      MobileAds.initialize(this@MainActivity, InitializationConfig.Builder("SAMPLE_APP_ID").build()) {
        initializationStatus ->
        for ((adapterName, adapterStatus) in initializationStatus.adapterStatusMap) {
          Log.d(
            "MyApp",
            String.format(
              "Adapter name: %s, Status code: %s, Status string: %s, Latency: %d",
              adapterName,
              adapterStatus.initializationState,
              adapterStatus.description,
              adapterStatus.latency,
            ),
          )
        }
        // Adapter initialization is complete.
      }
      // Other methods on MobileAds can now be called.
    }
  }
}

자바

import com.google.android.libraries.ads.mobile.sdk.MobileAds;
import com.google.android.libraries.ads.mobile.sdk.initialization.AdapterStatus;
import com.google.android.libraries.ads.mobile.sdk.initialization.InitializationConfig;

public class MainActivity extends AppCompatActivity {
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    new Thread(
            () -> {
              // Initialize Google Mobile Ads SDK (beta) on a background thread.
              MobileAds.initialize(
                  this,
                  new InitializationConfig.Builder("SAMPLE_APP_ID")
                      .build(),
                  initializationStatus -> {
                    Map<String, AdapterStatus> adapterStatusMap =
                        initializationStatus.getAdapterStatusMap();
                    for (String adapterClass : adapterStatusMap.keySet()) {
                      AdapterStatus adapterStatus = adapterStatusMap.get(adapterClass);
                      Log.d(
                          "MyApp",
                          String.format(
                              "Adapter name: %s, Status code: %s, Status description: %s,"
                                  + " Latency: %d",
                              adapterClass,
                              adapterStatus.getInitializationState(),
                              adapterStatus.getDescription(),
                              adapterStatus.getLatency()));
                    }
                    // Adapter initialization is complete.
                  });
              // Other methods on MobileAds can now be called.
            })
        .start();
  }
}

미디에이션 통합에서 com.google.android.gms 모듈 제외

미디에이션 어댑터는 현재 Google 모바일 광고 SDK (베타)에 계속 종속됩니다. 하지만 Google 모바일 광고 SDK (베타)에는 미디에이션 어댑터에 필요한 모든 클래스가 포함되어 있습니다. 중복된 심볼과 관련된 컴파일 오류를 방지하려면 현재 Google 모바일 광고 SDK (베타)가 미디에이션 어댑터에 의해 종속 항목으로 가져와지지 않도록 제외해야 합니다.

앱 수준 build.gradle 파일에서 play-services-adsplay-services-ads-lite 모듈을 모든 종속 항목에서 전역적으로 제외합니다.

configurations {
  all {
    exclude(group = "com.google.android.gms", module = "play-services-ads")
    exclude(group = "com.google.android.gms", module = "play-services-ads-lite")
  }
}

어느 광고 네트워크 어댑터 클래스가 광고를 로드했는지 확인하기

다음은 배너 광고의 광고 네트워크 클래스 이름을 기록하는 샘플 코드입니다.

Kotlin

BannerAd.load(
  BannerAdRequest.Builder("AD_UNIT_ID", AdSize.BANNER).build(),
  object : AdLoadCallback<BannerAd> {
    override fun onAdLoaded(ad: BannerAd) {
      Log.d(
        "MyApp", "Adapter class name: " +
          ad.getResponseInfo().mediationAdapterClassName
      )
    }
  }
)

자바

BannerAd.load(
  new BannerAdRequest.Builder("AD_UNIT_ID", AdSize.BANNER).build(),
  new AdLoadCallback<BannerAd>() {
    @Override
    public void onAdLoaded(@NonNull BannerAd ad) {
      Log.d("MyApp",
          "Adapter class name: " + ad.getResponseInfo().getMediationAdapterClassName());
    }
  }
);

모든 서드 파티 광고 소스 UI에서 AdMob 미디에이션에 사용되는 배너 광고 단위에 대한 새로고침을 사용 중지하세요. 배너 광고 단위의 새로고침 빈도에 따라 AdMob에서도 새로고침을 실행하므로 위와 같이 조치하면 이중 새로고침을 방지할 수 있습니다.

미국 주 개인 정보 보호법 및 GDPR

미국 주 개인 정보 보호법 또는 개인 정보 보호법 (GDPR)을 준수해야 하는 경우 미국 주 규정 설정 또는 GDPR 설정의 단계에 따라 AdMob 개인 정보 보호 및 메시지의 미국 주 또는 GDPR 광고 파트너 목록에 미디에이션 파트너를 추가하세요. 이렇게 하지 않으면 파트너가 앱에 광고를 게재하지 못할 수 있습니다.

Google 사용자 메시지 플랫폼(UMP) SDK를 사용하여 제한적인 데이터 처리 (RDP)를 사용 설정하고 GDPR 동의를 얻는 방법을 자세히 알아보세요.