아이콘 광고는 운영체제 사용자 환경을 보완하는 작은 앱 아이콘 게재위치이며 잠금 화면, 공유 화면과 같은 대부분의 OS 수준 활동을 지원할 수 있습니다. 아이콘 광고는 개별적으로 또는 여러 그룹으로 표시할 수 있습니다. 각 광고는 앱에서 렌더링해야 하는 텍스트 및 문자열 요소 집합을 제공합니다. 다음 이미지는 앱 폴더에 표시된 아이콘 광고를 보여줍니다.
|
|
|
|
이 가이드에서는 아이콘 광고를 요청하고 표시하는 방법을 보여줍니다.
기본 요건
시작하기 전에 GMA Next-Gen SDK 0.8.0-alpha01 이상을 사용해야 합니다.
항상 테스트 광고로 테스트
앱을 빌드하고 테스트할 때는 운영 중인 실제 광고 대신 테스트 광고를 사용하세요. 테스트 광고를 사용하지 않으면 계정이 정지될 수 있습니다.
광고 단위를 사용하고 테스트 기기를 사용 설정하여 테스트 광고를 가져오거나 Android 아이콘 광고용 전용 테스트 광고 단위 ID를 사용하세요.
ca-app-pub-3940256099942544/1476272466
아이콘 광고 로드
아이콘 광고 요청으로 아이콘 광고를 로드하고 광고 로드 이벤트를 처리합니다.
Kotlin
private fun loadIconAd() {
val request =
IconAdRequest.Builder(AD_UNIT_ID)
// The "AdChoices" badge is rendered at the top right corner of the icon ad
// if left unspecified.
.setAdChoicesPlacement(AdChoicesPlacement.BOTTOM_RIGHT)
// It is recommended to specify the placement of your icon ad
// to help Google optimize your icon ad performance.
.setIconAdPlacement(IconAdPlacement.BROWSER)
.build()
IconAd.load(
request,
object : AdLoadCallback<IconAd> {
override fun onAdFailedToLoad(adError: LoadAdError) {
Log.w(Constant.TAG, "Icon ad failed to load: $adError")
showToast("Icon ad failed to load.")
}
override fun onAdLoaded(ad: IconAd) {
Log.d(Constant.TAG, "Icon ad loaded")
// Always call destroy() on ads on removal.
iconAd?.destroy()
iconAd = ad
setAdEventCallback(ad)
displayIconAd(ad)
}
},
)
}
자바
private void loadIconAd() {
IconAdRequest request =
new IconAdRequest.Builder(AD_UNIT_ID)
// The "AdChoices" badge is rendered at the top right corner of the icon ad
// if left unspecified.
.setAdChoicesPlacement(AdChoicesPlacement.BOTTOM_RIGHT)
// It is recommended to specify the placement of your icon ad
// to help Google optimize your icon ad performance.
.setIconAdPlacement(IconAdPlacement.BROWSER)
.build();
IconAd.load(
request,
new AdLoadCallback<IconAd>() {
@Override
public void onAdFailedToLoad(@NonNull LoadAdError adError) {
Log.w(Constant.TAG, "Icon ad failed to load :" + adError);
showToast("Icon ad failed to load with error code: " + adError.getCode());
}
@Override
public void onAdLoaded(@NonNull IconAd ad) {
Log.d(Constant.TAG, "Icon ad loaded.");
// Always call destroy() on ads on removal.
if (iconAd != null) {
iconAd.destroy();
}
iconAd = ad;
setAdEventCallback(ad);
displayIconAd(ad);
}
});
}
아이콘 광고 뷰 만들기
아이콘 광고에서는 확장 소재의 루트 요소로 IconAdView를 사용해야 합니다. 아이콘 광고 뷰 내에 광고의 모든 시각적 요소를 배치합니다.
다음 예에서는 아이콘 광고 뷰를 만드는 레이아웃을 보여줍니다.
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.libraries.ads.mobile.sdk.iconad.IconAdView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/icon_ad_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#00FFC107"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/ad_badge"
android:width="15dp"
android:height="15dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFC107"
android:text="Ad"
android:textColor="#FFFFFF"
android:textSize="12sp" />
<TextView
android:id="@+id/ad_headline"
android:textStyle="normal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:autoText="true"
android:inputType="text|textMultiLine"
android:textColor="#808080"
android:textSize="12sp" />
</LinearLayout>
<com.google.android.material.imageview.ShapeableImageView xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ad_icon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:background="@android:color/holo_green_light"
android:contentDescription="@string/content_description_icon_ad"
android:theme="@style/Theme.AppCompat.Light"
app:shapeAppearanceOverlay="@style/roundedCorners"
app:strokeColor="@null" />
<RatingBar
android:id="@+id/ad_stars"
style="?android:attr/ratingBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:isIndicator="true"
android:numStars="5"
android:stepSize="0.5" />
<Button
android:id="@+id/ad_call_to_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:textSize="12sp" />
</LinearLayout>
</com.google.android.libraries.ads.mobile.sdk.iconad.IconAdView>
화면에 아이콘 광고 표시하기
화면에 아이콘 광고를 표시하려면 다음 단계를 완료하세요.
아이콘 광고 뷰를 확장하고 뷰 계층 구조에 추가합니다.
각 하위 뷰를 해당 아이콘 광고 확장 소재로 채웁니다.
다음 예에서는 화면에 아이콘 광고를 표시하는 이전 단계를 다룹니다.
Kotlin
val iconAdViewBinding = IconAdBinding.inflate(layoutInflater)
// Add the ad view to the active view hierarchy.
binding.iconAdContainer.addView(iconAdViewBinding.root)
val iconAdView = iconAdViewBinding.root
// Populate the view elements with their respective icon ad asset.
iconAdView.callToActionView = iconAdViewBinding.adCallToAction
iconAdView.headlineView = iconAdViewBinding.adHeadline
iconAdView.iconView = iconAdViewBinding.adIcon
iconAdView.starRatingView = iconAdViewBinding.adStars
자바
IconAdBinding iconAdViewBinding = IconAdBinding.inflate(getLayoutInflater());
// Add the ad view to the active view hierarchy.
binding.iconAdContainer.addView(iconAdViewBinding.getRoot());
IconAdView iconAdView = iconAdViewBinding.getRoot();
// Populate the view elements with their respective icon ad asset.
iconAdView.setCallToActionView(iconAdViewBinding.adCallToAction);
iconAdView.setHeadlineView(iconAdViewBinding.adHeadline);
iconAdView.setIconView(iconAdViewBinding.adIcon);
iconAdView.setStarRatingView(iconAdViewBinding.adStars);
아이콘 광고를 클릭 가능한 상태로 설정하기
GMA Next-Gen SDK는 registerIconAd()가 호출될 때 매핑되는 각 확장 소재 뷰의 클릭 리스너를 등록합니다. 아이콘 광고를 등록하기 전에 아이콘 광고 뷰 속성을 뷰 계층 구조의 해당 뷰에 매핑합니다.
Kotlin
// Map each asset view property to the corresponding view in your view hierarchy.
iconAdViewBinding.adCallToAction.text = iconAd.callToAction
iconAdViewBinding.adHeadline.text = iconAd.headline
iconAdViewBinding.adIcon.setImageDrawable(iconAd.icon.drawable)
iconAd.starRating?.toFloat().also { value ->
if (value != null) {
iconAdViewBinding.adStars.rating = value
}
}
// Register the icon ad with the view presenting it.
iconAdView.registerIconAd(iconAd)
자바
// Map each asset view property to the corresponding view in your view hierarchy.
iconAdViewBinding.adCallToAction.setText(iconAd.getCallToAction());
iconAdViewBinding.adHeadline.setText(iconAd.getHeadline());
iconAdViewBinding.adIcon.setImageDrawable(iconAd.getIcon().getDrawable());
if (iconAd.getStarRating() != null) {
iconAdViewBinding.adStars.setRating(iconAd.getStarRating().floatValue());
}
// Register the icon ad with the view presenting it.
iconAdView.registerIconAd(iconAd);
선택사항: 아이콘 광고 이벤트 콜백 설정하기
아이콘 광고 수명 주기 이벤트를 처리하려면 이벤트 콜백을 설정하세요.
Kotlin
iconAd.adEventCallback =
object : IconAdEventCallback {
override fun onAdShowedFullScreenContent() {
// Icon ad showed full screen content.
}
override fun onAdDismissedFullScreenContent() {
// Icon ad dismissed full screen content.
}
override fun onAdFailedToShowFullScreenContent(
fullScreenContentError: FullScreenContentError
) {
// Icon ad failed to show full screen content.
}
override fun onAdImpression() {
// Icon ad recorded an impression.
}
override fun onAdClicked() {
// Icon ad recorded a click.
}
override fun onAdPaid(value: AdValue) {
// Icon ad estimated to have earned money.
}
}
자바
iconAd.setAdEventCallback(
new IconAdEventCallback() {
@Override
public void onAdShowedFullScreenContent() {
// Icon ad showed full screen content.
}
@Override
public void onAdDismissedFullScreenContent() {
// Icon ad dismissed full screen content.
}
@Override
public void onAdFailedToShowFullScreenContent(
@NonNull FullScreenContentError fullScreenContentError) {
// Icon ad failed to show full screen content.
}
@Override
public void onAdImpression() {
// Icon ad recorded an impression.
}
@Override
public void onAdClicked() {
// Icon ad recorded a click.
}
@Override
public void onAdPaid(@NonNull AdValue value) {
// Icon ad estimated to have earned money.
}
});
실적 최적화하기
다음 섹션에서는 아이콘 광고의 실적을 최적화하기 위한 구현 단계(선택사항)를 설명합니다.
상관자를 사용하여 여러 광고 로드하기
함께 표시할 여러 아이콘 광고를 로드할 때는 동일한 상관자 값을 통해 순차적으로 요청하여 로드된 광고가 고유하도록 합니다. 상관자 수명 기간은 10초입니다. 서버는 10초 이상 간격으로 이루어진 요청을 상관관계가 있는 것으로 간주하지 않습니다.
다음 예는 광고 요청에서 상관자 값을 설정하는 방법을 보여줍니다.
Kotlin
val correlator = Correlator.generateCorrelator()
val request =
IconAdRequest.Builder("ca-app-pub-3940256099942544/1476272466")
.setCorrelator(correlator)
.build()
자바
Correlator correlator = Correlator.generateCorrelator();
IconAdRequest request =
new IconAdRequest.Builder("ca-app-pub-3940256099942544/1476272466")
.setCorrelator(correlator)
.build();
아이콘 광고 게재위치 설정하기
Google에서 아이콘 광고 게재위치를 파악하여 아이콘 광고 실적을 최적화할 수 있도록 요청 시 아이콘 광고를 표시할 위치를 지정하는 것이 좋습니다.
사용 사례를 가장 잘 나타내는 IconAdPlacement enum 값을 사용합니다.
Kotlin
val request =
IconAdRequest.Builder("ca-app-pub-3940256099942544/1476272466")
.setIconAdPlacement(IconAdPlacement.BROWSER)
.build()
Java
IconAdRequest request =
new IconAdRequest.Builder("ca-app-pub-3940256099942544/1476272466")
.setIconAdPlacement(IconAdPlacement.BROWSER)
.build();