[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"Translation issue"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples/Code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
전면 광고(기존 API)
전면 광고는 호스트 앱의 인터페이스를 완전히 덮는 전체 화면 광고입니다.
일반적으로 활동이 바뀌는 시점 또는 게임에서 다음 레벨로 넘어갈 때처럼
앱 이용이 잠시 중단될 때 자연스럽게 광고가 게재됩니다.
앱에서 전면 광고가 표시될 때 사용자는 광고를 탭하여 도착 페이지로
이동하거나
광고를 닫고 앱으로 돌아갈 수 있습니다.
우수사례
class MainActivity : Activity() {
private lateinit var mInterstitialAd: InterstitialAd
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
MobileAds.initialize(this,
"ca-app-pub-3940256099942544~3347511713")
mInterstitialAd = InterstitialAd(this)
mInterstitialAd.adUnitId = "ca-app-pub-3940256099942544/1033173712"
mInterstitialAd.loadAd(AdRequest.Builder().build())
}
}
광고 게재
전면 광고는 앱 이용이 잠시 중단될 때 자연스럽게 표시되어야 합니다.
예를 들어 게임에서 다음 레벨로 넘어갈 때 또는 작업을 완료한 직후가 광고를 게재하기 좋은 시점입니다.
전면 광고를 표시하려면
isLoaded()
메서드를 사용하여 로드가 완료되었는지 확인한 다음
show()를 호출하세요.
이전 코드 예의 전면 광고가
다음과 같은 버튼의 OnClickListener에 표시될 수 있습니다.
자바
mMyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.");
}
}
});
Kotlin
mMyButton.setOnClickListener {
if (mInterstitialAd.isLoaded) {
mInterstitialAd.show()
} else {
Log.d("TAG", "The interstitial wasn't loaded yet.")
}
}
광고 이벤트
광고의 작동 방식을 추가로 맞춤설정하려는 경우 광고의 수명 주기에서 발생하는
여러 이벤트(예: 로드, 열기, 닫기)에 대해 설정해 보세요. AdListener
클래스를 통해 이러한 이벤트를
수신할 수
있습니다.
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.
}
@Override
public void onAdClicked() {
// Code to be executed when the user clicks on an ad.
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
@Override
public void onAdClosed() {
// Code to be executed when the interstitial ad is closed.
}
});
Kotlin
mInterstitialAd.adListener = object: AdListener() {
override fun onAdLoaded() {
// Code to be executed when an ad finishes loading.
}
override fun onAdFailedToLoad(errorCode: Int) {
// Code to be executed when an ad request fails.
}
override fun onAdOpened() {
// Code to be executed when the ad is displayed.
}
override fun onAdClicked() {
// Code to be executed when the user clicks on an ad.
}
override fun onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
override fun onAdClosed() {
// Code to be executed when the interstitial ad is closed.
}
}
AdListener에서
재정의할 수 있는 각 메서드가 광고 수명 주기에서
발생하는 이벤트 하나에 해당됩니다.
전면 광고는 자연스러운 전환 지점이 있는 앱에서 최대의 효과를 발휘합니다.
자연스러운 전환 지점이란 이미지 공유, 게임 레벨 달성처럼
앱에서 작업이 완료되는 순간을 말합니다. 이러한 경우는
사용자도 쉬어가는 지점으로 인식하므로 사용자 경험에 지장을 주지 않고
전면 광고를 부담 없이 표시할 수 있습니다. 앱의 이용 과정에서
어떤 지점에 전면 광고를 표시해야 가장 자연스러우며
사용자가 어떻게 반응할지 생각해 보세요.
전면 광고를 게재하려면 앱 사용을 잠시 중단하는 순간이 있어야 합니다.
텍스트, 이미지, 동영상 등 전면 광고에는 다양한 유형이
있습니다.
앱에서 전면 광고를 표시할 때는 광고에서
리소스를 활용할 수 있도록 일부 리소스의 이용을
중지해야 합니다. 예를 들어 전면 광고를 표시하도록 호출할 때
앱에서 재생되는 오디오 출력을 일시중지해야 합니다.
사용자가 광고와의 상호작용을 마칠 때 호출되는
onAdClosed()
이벤트 핸들러를 통해
사운드 재생을 재개할 수 있습니다. 또한 광고가 표시되는 동안에는
강도 높은 계산 작업(예: 게임 루프)을
잠시 중단하는 것이 좋습니다.
이렇게 하면 그래픽이 느려지거나 응답이 없는 현상
또는 동영상 끊김 등의 문제가 사라집니다.
충분한 로드 시간을 확보하세요.
전면 광고를 적절한 시점에 표시하는 것뿐 아니라
광고 로드가 너무 지연되지 않게 하는 것도
중요합니다. show()를 호출하기 전에
loadAd()를 호출하면 앱에서 전면 광고가
완전히 로드된 상태가 되어 광고를 게재할 수 있는 시점에 전면 광고를 바로 표시할 수 있습니다.
광고를 과도하게 게재하면 안 됩니다.
앱에 전면 광고를 더 많이 게재할수록 수익이 늘어난다고 생각할 수
있겠지만, 이렇게 하면 사용자 환경이 악화되고 클릭률이 떨어지기도
합니다. 사용자의 원활한 앱 사용에 지장을 주지 않는 범위에서
게재 빈도를 조절하시기 바랍니다.
소스 코드
MyActivity.java
/*
* Copyright (C) 2013 Google, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.android.gms.example.interstitialexample;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.LoadAdError;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
/**
* Main Activity. Inflates main activity xml.
*/
public class MyActivity extends AppCompatActivity {
private static final long GAME_LENGTH_MILLISECONDS = 3000;
private static final String AD_UNIT_ID = "ca-app-pub-3940256099942544/1033173712";
private InterstitialAd interstitialAd;
private CountDownTimer countDownTimer;
private Button retryButton;
private boolean gameIsInProgress;
private long timerMilliseconds;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
// Initialize the Mobile Ads SDK.
MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {}
});
// Create the InterstitialAd and set the adUnitId.
interstitialAd = new InterstitialAd(this);
// Defined in res/values/strings.xml
interstitialAd.setAdUnitId(AD_UNIT_ID);
interstitialAd.setAdListener(
new AdListener() {
@Override
public void onAdLoaded() {
Toast.makeText(MyActivity.this, "onAdLoaded()", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdFailedToLoad(LoadAdError loadAdError) {
String error =
String.format(
"domain: %s, code: %d, message: %s",
loadAdError.getDomain(), loadAdError.getCode(), loadAdError.getMessage());
Toast.makeText(
MyActivity.this, "onAdFailedToLoad() with error: " + error, Toast.LENGTH_SHORT)
.show();
}
@Override
public void onAdClosed() {
startGame();
}
});
// Create the "retry" button, which tries to show an interstitial between game plays.
retryButton = findViewById(R.id.retry_button);
retryButton.setVisibility(View.INVISIBLE);
retryButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showInterstitial();
}
});
startGame();
}
private void createTimer(final long milliseconds) {
// Create the game timer, which counts down to the end of the level
// and shows the "retry" button.
if (countDownTimer != null) {
countDownTimer.cancel();
}
final TextView textView = findViewById(R.id.timer);
countDownTimer = new CountDownTimer(milliseconds, 50) {
@Override
public void onTick(long millisUnitFinished) {
timerMilliseconds = millisUnitFinished;
textView.setText("seconds remaining: " + ((millisUnitFinished / 1000) + 1));
}
@Override
public void onFinish() {
gameIsInProgress = false;
textView.setText("done!");
retryButton.setVisibility(View.VISIBLE);
}
};
}
@Override
public void onResume() {
// Start or resume the game.
super.onResume();
if (gameIsInProgress) {
resumeGame(timerMilliseconds);
}
}
@Override
public void onPause() {
// Cancel the timer if the game is paused.
countDownTimer.cancel();
super.onPause();
}
private void showInterstitial() {
// Show the ad if it's ready. Otherwise toast and restart the game.
if (interstitialAd != null && interstitialAd.isLoaded()) {
interstitialAd.show();
} else {
Toast.makeText(this, "Ad did not load", Toast.LENGTH_SHORT).show();
startGame();
}
}
private void startGame() {
// Request a new ad if one isn't already loaded, hide the button, and kick off the timer.
if (!interstitialAd.isLoading() && !interstitialAd.isLoaded()) {
AdRequest adRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(adRequest);
}
retryButton.setVisibility(View.INVISIBLE);
resumeGame(GAME_LENGTH_MILLISECONDS);
}
private void resumeGame(long milliseconds) {
// Create a new timer for the correct length and start it.
gameIsInProgress = true;
timerMilliseconds = milliseconds;
createTimer(milliseconds);
countDownTimer.start();
}
}
MainActivity.kt
package com.google.android.gms.example.interstitialexample
import android.os.Bundle
import android.os.CountDownTimer
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.gms.ads.AdListener
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.InterstitialAd
import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.MobileAds
import com.google.android.gms.ads.RequestConfiguration
import kotlinx.android.synthetic.main.activity_main.*
const val GAME_LENGTH_MILLISECONDS = 3000L
const val AD_UNIT_ID = "ca-app-pub-3940256099942544/1033173712"
class MainActivity : AppCompatActivity() {
private lateinit var mInterstitialAd: InterstitialAd
private var mCountDownTimer: CountDownTimer? = null
private var mGameIsInProgress = false
private var mTimerMilliseconds = 0L
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Initialize the Mobile Ads SDK.
MobileAds.initialize(this) {}
// Set your test devices. Check your logcat output for the hashed device ID to
// get test ads on a physical device. e.g.
// "Use RequestConfiguration.Builder().setTestDeviceIds(Arrays.asList("ABCDEF012345"))
// to get test ads on this device."
MobileAds.setRequestConfiguration(
RequestConfiguration.Builder()
.setTestDeviceIds(listOf("ABCDEF012345"))
.build()
)
// Create the InterstitialAd and set it up.
mInterstitialAd = InterstitialAd(this).apply {
adUnitId = AD_UNIT_ID
adListener = (
object : AdListener() {
override fun onAdLoaded() {
Toast.makeText(this@MainActivity, "onAdLoaded()", Toast.LENGTH_SHORT).show()
}
override fun onAdFailedToLoad(loadAdError: LoadAdError) {
val error = "domain: ${loadAdError.domain}, code: ${loadAdError.code}, " +
"message: ${loadAdError.message}"
Toast.makeText(
this@MainActivity,
"onAdFailedToLoad() with error $error",
Toast.LENGTH_SHORT
).show()
}
override fun onAdClosed() {
startGame()
}
}
)
}
// Create the "retry" button, which triggers an interstitial between game plays.
retry_button.visibility = View.INVISIBLE
retry_button.setOnClickListener { showInterstitial() }
// Kick off the first play of the "game."
startGame()
}
// Create the game timer, which counts down to the end of the level
// and shows the "retry" button.
private fun createTimer(milliseconds: Long) {
mCountDownTimer?.cancel()
mCountDownTimer = object : CountDownTimer(milliseconds, 50) {
override fun onTick(millisUntilFinished: Long) {
mTimerMilliseconds = millisUntilFinished
timer.text = "seconds remaining: ${ millisUntilFinished / 1000 + 1 }"
}
override fun onFinish() {
mGameIsInProgress = false
timer.text = "done!"
retry_button.visibility = View.VISIBLE
}
}
}
// Show the ad if it's ready. Otherwise toast and restart the game.
private fun showInterstitial() {
if (mInterstitialAd.isLoaded) {
mInterstitialAd.show()
} else {
Toast.makeText(this, "Ad wasn't loaded.", Toast.LENGTH_SHORT).show()
startGame()
}
}
// Request a new ad if one isn't already loaded, hide the button, and kick off the timer.
private fun startGame() {
if (!mInterstitialAd.isLoading && !mInterstitialAd.isLoaded) {
// Create an ad request.
val adRequest = AdRequest.Builder().build()
mInterstitialAd.loadAd(adRequest)
}
retry_button.visibility = View.INVISIBLE
resumeGame(GAME_LENGTH_MILLISECONDS)
}
private fun resumeGame(milliseconds: Long) {
// Create a new timer for the correct length and start it.
mGameIsInProgress = true
mTimerMilliseconds = milliseconds
createTimer(milliseconds)
mCountDownTimer?.start()
}
// Resume the game if it's in progress.
public override fun onResume() {
super.onResume()
if (mGameIsInProgress) {
resumeGame(mTimerMilliseconds)
}
}
// Cancel the timer if the game is paused.
public override fun onPause() {
mCountDownTimer?.cancel()
super.onPause()
}
}