onReady로 게임 로딩을 수동으로 시퀀싱
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
게임이 포함된 페이지가 처음 로드되면 여러 가지
비동기 이벤트가 발생합니다.
게임 로직과 광고 태그가 로드되고, Ad Placement API가
초기화되기 시작하며, 광고가 미리 로드됩니다. 따라서 페이지 로드 직후에
adBreak()
를 호출하면 API가 초기화되지 않았거나
광고가 미리 로드 완료되지 않았을 수 있습니다. API가 초기화되지 않았다면
호출이 실패하고 adBreakDone()
콜백을 등록한 경우
breakStatus
가 notReady
로 설정됩니다.
게임 로직을 Ad
Placement API의 초기화와 동기화해야 하는 경우 adConfig()
에 onReady()
콜백을 사용할 수 있습니다.
onReady()
는 다음과 같은 경우 Ad Placement API에서 호출합니다.
- 광고 태그가 로드된 경우
- Ad Placement API가 로드되고 초기화된 경우 및
adConfig()
를 사용하여
광고 미리 로드를 요청하고 완료한 경우
이 시점에서 Ad Placement API는 완전히 초기화됩니다. adBreak()
을 호출할 수 있으며
notReady
상태를 반환하지 않습니다. 하지만 항상 그렇듯이
adBreak()
를 통해 광고가 게재되지 않을 수도 있습니다(예: 게재할 수 있는 광고가 없음).
다음은 onReady()
의 사용을 보여주는 예입니다.
...
<script>
window.adsbygoogle = window.adsbygoogle || [];
var adBreak = adConfig = function(o) {adsbygoogle.push(o);}
...
function init() {
// Game start logic, show loading screen
adConfig({
preloadAdBreaks: 'on',
onReady: showAd
});
// Don't start the gameplay just yet, keep loading.
}
function showAd() {
// Show an ad
adBreak({
type: 'start',
adBreakDone: startGame, // always called, unblocks the game logic
...
});
}
...
</script>
참고: 페이지 로드 직후에 adBreak()
을 호출하는 가장 일반적인 사용 사례는 프리롤을 구현하는 것입니다. 여기에 설명된 방법으로 직접 만드는 대신 preroll
게재위치 유형을 꼭 사용하시기 바랍니다.
preroll
는 필요한 모든 미리 로드 및 제한 시간 로직을 자동으로 구현합니다. 게임에 프리롤을 사용하는 경우 onReady()
를 사용할 필요가 없습니다. 프리롤에 대해 자세히 알아보기
제한 시간
Ad Placement API 초기화가 지연되거나 완전히 로드되지 않는 경우
onReady()
가 호출되지 않을 수 있습니다. 게임이
제시간에 시작되도록 하려면 제한 시간을 설정하는 것이 좋습니다. onReady()
콜백을
수신한 경우 adBreak()를 호출하여 광고를 게재할 수 있습니다. 또는
광고 호출을 건너뛰고 게임을 로드해도 됩니다.
다음 예에는 제한 시간이 포함되며 이는
프리롤 배치로 구현된 로직과 유사합니다.
...
<script>
window.adsbygoogle = window.adsbygoogle || [];
var adBreak = adConfig = function(o) {adsbygoogle.push(o);}
...
function init() {
// Game start logic
let adConfigPromise =
new Promise((resolve, reject) => adConfig({
preloadAdBreaks: 'on',
onReady: () => resolve(true)
}));
let timeoutPromise =
new Promise((resolve, reject) => {
setTimeout(() => {
resolve(false);
}, 2000);
});
// Whatever happens first resolves this promise.
Promise.race([
adConfigPromise,
timeoutPromise
]).then((shouldShowPreRoll) => {
if (shouldShowPreRoll) {
showPreRoll();
} else {
startGame();
}
});
}
function showPreRoll() {
// Show ad
adBreak({
type: 'start',
adBreakDone: startGame, // always called, unblocks the game logic
...
});
}
...
</script>
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003eThe Ad Placement API may not be immediately ready after page load, leading to potential ad break failures if called too soon.\u003c/p\u003e\n"],["\u003cp\u003eUse the \u003ccode\u003eonReady()\u003c/code\u003e callback with \u003ccode\u003eadConfig()\u003c/code\u003e to synchronize your game logic with the Ad Placement API initialization, ensuring ads are preloaded and ready.\u003c/p\u003e\n"],["\u003cp\u003eFor preroll ads, utilize the dedicated \u003ccode\u003epreroll\u003c/code\u003e placement type instead of manually managing preloading and timeouts.\u003c/p\u003e\n"],["\u003cp\u003eImplement a timeout mechanism with \u003ccode\u003eonReady()\u003c/code\u003e to avoid indefinite delays and ensure your game starts promptly, even if ad initialization fails.\u003c/p\u003e\n"]]],["The Ad Placement API loads asynchronously with game logic and ads. Calling `adBreak()` immediately might fail if the API hasn't initialized or ads aren't preloaded. Use `onReady()` in `adConfig()` to ensure the API is ready, including tag loading, initialization, and ad preloading. `onReady()` is not guaranteed to be called if the API fails to load entirely. To handle potential delays, implement a timeout using `Promise.race`, proceeding with or without an ad call based on the timeout.\n"],null,["# Manually sequence game loading with onReady\n\nWhen the page containing your game first loads there are a number of\nasynchronous events taking place.\n\nYour game logic loads, the ads tag loads, the Ad Placement API starts\ninitialising, and ads can be preloaded. As a result, if you call `adBreak()`\nvery soon after page load, there is a chance that the API may not have\ninitialized or that ads have not finished preloading. If the API has not\ninitialized the call will fail, and if you've registered an `adBreakDone()`\ncallback, the `breakStatus` will be set to `notReady`.\n\nIf you need to synchronize your game logic with the initialization of the Ad\nPlacement API, you can use the `onReady()` callback to `adConfig()`.\n\n`onReady()` is called by the Ad Placement API when:\n\n- the ad's tag has loaded,\n- the Ad Placement API has loaded and initialized, and\n- ads have finished preloading---if you requested preloading using `adConfig()`\n\nAt this point the Ad Placement API is fully initialized. You can call\n`adBreak()`, and it won't return a `notReady` status. But as always `adBreak()`\nmay still not show an ad (for example, there wasn't an ad available).\n\nHere's an example that shows the use of `onReady()`: \n\n ...\n \u003cscript\u003e\n window.adsbygoogle = window.adsbygoogle || [];\n var adBreak = adConfig = function(o) {adsbygoogle.push(o);}\n ...\n function init() {\n // Game start logic, show loading screen\n adConfig({\n preloadAdBreaks: 'on',\n onReady: showAd\n });\n // Don't start the gameplay just yet, keep loading.\n }\n\n function showAd() {\n // Show an ad\n adBreak({\n type: 'start',\n adBreakDone: startGame, // always called, unblocks the game logic\n ...\n });\n }\n ...\n \u003c/script\u003e\n\n**Note** : the most common use case to call `adBreak()` very soon after page load is to implement a preroll. We **strongly recommend** you use a `preroll` placement type rather than trying to create your own using the methods described here.\n\n`preroll` automatically implements all of the required preloading and timeout logic. If you use a preroll with your game, you don't need to use `onReady()`. Learn more about [preroll](/ad-placement/docs/preload-ads)\n\nTimeouts\n--------\n\n`onReady()` is not guaranteed to be called if the Ad Placement API\ninitialisation is delayed or fails to load entirely. To ensure your game starts\nin a timely fashion, you may want to set up a timeout. If you receive the\n`onReady()`callback, then you can call adBreak() to place the ad, otherwise you\ncan skip the ad call and proceed to load your game.\n\nThe following example includes a timeout---and is similar to the logic\nimplemented by a preroll placement: \n\n ...\n \u003cscript\u003e\n window.adsbygoogle = window.adsbygoogle || [];\n var adBreak = adConfig = function(o) {adsbygoogle.push(o);}\n ...\n function init() {\n // Game start logic\n let adConfigPromise =\n new Promise((resolve, reject) =\u003e adConfig({\n preloadAdBreaks: 'on',\n onReady: () =\u003e resolve(true)\n }));\n let timeoutPromise =\n new Promise((resolve, reject) =\u003e {\n setTimeout(() =\u003e {\n resolve(false);\n }, 2000);\n });\n // Whatever happens first resolves this promise.\n Promise.race([\n adConfigPromise,\n timeoutPromise\n ]).then((shouldShowPreRoll) =\u003e {\n if (shouldShowPreRoll) {\n showPreRoll();\n } else {\n startGame();\n }\n });\n }\n\n function showPreRoll() {\n // Show ad\n adBreak({\n type: 'start',\n adBreakDone: startGame, // always called, unblocks the game logic\n ...\n });\n }\n ...\n \u003c/script\u003e"]]