廣告設定
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
adConfig() 呼叫會將遊戲的目前設定傳達給 Ad Placement API。Ad Placement API 可藉此調整預先載入廣告的方式,並篩選所要求的廣告類型,確保廣告適合放送 (例如需要音效的影片廣告)。
函式簽章:
adConfig({
preloadAdBreaks: 'on|auto', // Ad preloading strategy
sound: 'on|off' // This game has sound
onReady: () => {}, // Called when API has initialised and adBreak() is ready
});
adConfig 參數
名稱 |
類型 |
說明 |
sound |
字串 |
(選用) 遊戲目前是否正在播放音效。值: - on (預設) - off 這項呼叫會指定遊戲是否支援音效,以及在呼叫 adBreak() 前是否已啟用音效 (即取消靜音)。這有助於 Ad Placement API 為遊戲選取合適的廣告類型。 遊戲的音效狀態變更時,請立即呼叫這個函式,因為 Ad Placement API 可能必須要求新的廣告素材,這樣才能有充足的時間完成這項作業。
預設值為開啟音效。因此,大多數遊戲在開始宣告已啟用音效時,都需要呼叫 adConfig() 。 |
preloadAdBreaks |
字串 |
(選用) 廣告是否應一律在首次呼叫 adBreak() 前預先載入。值: - on - auto (預設)
預設值 auto 會將決策權交給 Ad Placement API。preloadAdBreaks 只能透過 adConfig() 設定一次,之後傳遞至 preloadAdBreaks 的值不會生效。 在首次呼叫 adBreak() 後設定 preloadAdBreaks 不會生效。 |
onReady |
字串 |
(選用):API 初始化並完成預先載入廣告後 (如果您使用上述 preloadAdBreaks 要求預先載入),系統就會呼叫這個方法。 |
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[[["\u003cp\u003e\u003ccode\u003eadConfig()\u003c/code\u003e is used to inform the Ad Placement API about the game's settings, such as sound and ad preloading preferences, for better ad selection and delivery.\u003c/p\u003e\n"],["\u003cp\u003eThe API uses this information to optimize ad preloading and ensure ads are suitable for the game's context, like avoiding sound-based ads in silent games.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can specify whether the game has sound enabled using the \u003ccode\u003esound\u003c/code\u003e parameter and control ad preloading behavior with \u003ccode\u003epreloadAdBreaks\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eAn optional \u003ccode\u003eonReady\u003c/code\u003e callback can be provided to notify the game when the API is initialized and ad preloading is complete, if requested.\u003c/p\u003e\n"]]],["The `adConfig()` function communicates the game's settings to the Ad Placement API. It accepts parameters to configure ad behavior: `sound` (specifying if sound is 'on' or 'off'), `preloadAdBreaks` ('on' or 'auto' for preloading ads), and `onReady` (a callback after initialization). `sound` informs the API of the game's sound capability and status, influencing ad selection. `preloadAdBreaks` dictates ad preloading strategy, set only once.\n"],null,["# adConfig\n\nThe **adConfig()** call communicates the game's current configuration to the\nAd Placement API. The Ad Placement API can use this to tune the way it preloads\nads and to filter the kinds of ads it requests so they're suitable (eg. video\nads that require sound).\n\nFunction signature: \n\n adConfig({\n preloadAdBreaks: 'on|auto', // Ad preloading strategy\n sound: 'on|off' // This game has sound\n onReady: () =\u003e {}, // Called when API has initialised and adBreak() is ready\n });\n\nadConfig parameters\n-------------------\n\n| Name | Type | Description |\n|-------------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `sound` | string | **(OPTIONAL)** Whether the game is currently playing sound. Values: - `on` (default) - `off` This call specifies whether your game is capable of sound, and whether the sound was enabled (ie unmuted) before the call to `adBreak()`. This helps the Ad Placement API to select the right kind of ad for your game. Call this function as soon as the sound state of your game changes, as the Ad Placement API may have to request new creatives, and this gives it the maximum amount of time to do so. The default value is sound on. So most games will need to make a call to `adConfig()` when they start to declare that they have sound enabled. |\n| `preloadAdBreaks` | string | **(OPTIONAL)** Whether ads should always be preloaded before the first call to `adBreak()`. Values: - `on` - `auto` (default) The default value of `auto` leaves the decision up to the Ad Placement API. `preloadAdBreaks` can be set only once with `adConfig()`, and further values passed to `preloadAdBreaks` have no effect. Setting `preloadAdBreaks` after the first call to `adBreak()` has no effect. |\n| `onReady` | string | **(OPTIONAL)** Called when the API has initialized and has finished preloading ads (if you requested preloading using the `preloadAdBreaks` above). |"]]