adConfig
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
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 决定。只能使用 adConfig() 设置 preloadAdBreaks 一次,之后传递到 preloadAdBreaks 的值没有任何作用。 在首次调用 adBreak() 后设置 preloadAdBreaks 不会产生任何影响。 |
onReady |
字符串 |
(可选)在 API 完成初始化并预加载广告后调用(如果您使用上面的 preloadAdBreaks 请求预加载)。 |
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):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). |"]]