> 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/ads/googleadmob.showappsintossadmob.md).

# GoogleAdMob.showAppsInTossAdMob

### 功能说明

`GoogleAdMob.loadAppsInTossAdMob`使用它预先加载的 AdMob 广告向用户展示。广告展示过程中发生的事件会 `onEvent` 以回调形式按顺序传递。

以事件风格运行，并将解除 AppBridge 回调的函数作为返回值。广告关闭后请务必解除。

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

### 类型

```ts
GoogleAdMob.showAppsInTossAdMob(params: ShowAdMobParams): () => void;
```

**Params**

```ts
interface ShowAdMobParams {
  options: ShowAdMobOptions;
  onEvent: (event: ShowAdMobEvent) => void;
  onError: (error: unknown) => void;
}

type ShowAdMobOptions = {
  /** 与 loadAppsInTossAdMob 中使用的广告组 ID 相同。 */
  adGroupId: string;
};

type ShowAdMobEvent =
  | { type: "requested" }
  | { type: "show" }
  | { type: "impression" }
  | { type: "clicked" }
  | { type: "dismissed" }
  | { type: "failedToShow" }
  | {
      type: "userEarnedReward";
      data: { unitType: string; unitAmount: number };
    };
```

事件 `类型` 值：

| 类型                 | 说明               |
| ------------------ | ---------------- |
| `requested`        | 请求展示广告成功了        |
| `show`             | 广告已显示在屏幕上        |
| `impression`       | 已记录广告曝光（产生收益的时点） |
| `clicked`          | 用户点击了广告          |
| `dismissed`        | 用户关闭了广告          |
| `failedToShow`     | 广告展示失败了          |
| `userEarnedReward` | 用户获得了奖励（仅限奖励广告）  |

**Response**

用于解除 AppBridge 回调的函数(`() => void`）作为返回值。

### 错误

如果广告展示失败 `failedToShow` 会通过事件或 `onError` 回调传递。奖励广告 `userEarnedReward` 只有在该事件发生时才应发放奖励。 `dismissed`仅靠它无法判断用户是否完整看完广告。

### 示例代码

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

const button = document.querySelector("#show-ad");

button.addEventListener("click", () => {
  const cleanup = GoogleAdMob.showAppsInTossAdMob({
    options: { adGroupId: "AD_GROUP_ID" },
    onEvent: (event) => {
      switch (event.type) {
        case "userEarnedReward":
          console.log(
            "获得奖励：",
            event.data.unitType,
            event.data.unitAmount,
          );
          break;
        case "dismissed":
          console.log("广告已关闭。");
          cleanup();
          break;
        case "failedToShow":
          console.error("广告展示失败了。");
          cleanup();
          break;
      }
    },
    onError: (error) => {
      console.error(error);
      cleanup();
    },
  });
});
```


---

# 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/ads/googleadmob.showappsintossadmob.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.
