> For the complete documentation index, see [llms.txt](https://developers-apps-in-toss.toss.im/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/sdk/domains-api/guang-gao/googleadmob.loadappsintossadmob.md).

# GoogleAdMob.loadAppsInTossAdMob

### 功能说明

Google AdMob 广告会预先加载，准备好在需要广告的时刻立即展示。广告成功加载后 `onEvent` 通过回调 `type: 'loaded'` 会传递事件。

调用前 `GoogleAdMob.loadAppsInTossAdMob.isSupported()`可通过它确认是否支持。

### 类型

```ts
GoogleAdMob.loadAppsInTossAdMob(params: LoadAdMobParams): () => void;
```

**参数**

```ts
interface LoadAdMobParams {
  options: LoadAdMobOptions;
  onEvent: (event: LoadAdMobEvent) => void;
  onError: (error: unknown) => void;
}

type LoadAdMobOptions = {
  /** 广告组 ID。请填写在 App in Toss 控制台中获取的值。 */
  adGroupId: string;
  /** 用于区分广告请求来源的值。 */
  referrer?: string | null;
};

type LoadAdMobEvent = {
  type: "loaded";
  data: LoadAdMobResult;
};

type LoadAdMobResult = {
  /** 广告组 ID。 */
  adGroupId: string;
  /** 广告 ID。 */
  adUnitId: string;
  /** 广告加载响应信息。 */
  responseInfo: {
    /** 广告网络响应信息数组。 */
    adNetworkInfoArray: AdNetworkResponseInfo[];
    /** 已加载的广告网络响应信息。 */
    loadedAdNetworkInfo: AdNetworkResponseInfo | null;
    /** 用于识别广告响应的 ID。 */
    responseId: string | null;
  };
};

type AdNetworkResponseInfo = {
  /** 广告源 ID。 */
  adSourceId: string;
  /** 广告源名称。 */
  adSourceName: string;
  /** 广告源实例 ID。 */
  adSourceInstanceId: string;
  /** 广告源实例名称。 */
  adSourceInstanceName: string;
  /** 广告网络类名称。 */
  adNetworkClassName: string | null;
};
```

**响应**

返回取消订阅函数(`() => void`)。调用后，之后到达的事件和错误将不会再通过回调传递。

### 错误

如果广告加载失败 `onError` 错误会通过回调传递。如果在非 Toss App WebView 环境中调用，则会在调用时发生错误。

### 示例代码

```js
import { Ads } from "@apps-in-toss/web-framework";

function loadAd() {
  if (!GoogleAdMob.loadAppsInTossAdMob.isSupported()) {
    console.warn("当前环境中无法使用 AdMob 广告。");
    return;
  }

  GoogleAdMob.loadAppsInTossAdMob({
    options: { adGroupId: "AD_GROUP_ID" },
    onEvent: (event) => {
      if (event.type === "loaded") {
        console.log("广告加载完成：", event.data.responseInfo.responseId);
      }
    },
    onError: (error) => {
      console.error("广告加载失败：", error);
    },
  });
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://developers-apps-in-toss.toss.im/documentation/api-and-sdk-zh/sdk/domains-api/guang-gao/googleadmob.loadappsintossadmob.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
