> 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-en/sdk/domains-api/ads/googleadmob.showappsintossadmob.md).

# GoogleAdMob.showAppsInTossAdMob

### Feature description

`GoogleAdMob.loadAppsInTossAdMob`Displays the AdMob ad preloaded with it to the user. Events that occur during the ad display process are `onEvent` passed sequentially as callbacks.

It works in an event style, and receives a function that releases the app bridge callback as the return value. Be sure to release it when the ad is closed.

Before calling `GoogleAdMob.showAppsInTossAdMob.isSupported()`You can check support with

### Type

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

**Params**

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

type ShowAdMobOptions = {
  /* This is the same ad group ID used in loadAppsInTossAdMob. */
  adGroupId: string;
};

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

Event `type` Value:

| type               | Description                                                              |
| ------------------ | ------------------------------------------------------------------------ |
| `requested`        | The request to show the ad succeeded                                     |
| `show`             | The ad was displayed on screen                                           |
| `impression`       | The ad impression was recorded (the point at which revenue is generated) |
| `clicked`          | The user clicked the ad                                                  |
| `dismissed`        | The user closed the ad                                                   |
| `failedToShow`     | Failed to show the ad                                                    |
| `userEarnedReward` | The user earned a reward (reward ads only)                               |

**Response**

Function that releases the app bridge callback (`() => void`) to release resources.

### Error

If ad display fails, `failedToShow` event or `onError` passed as a callback. Reward ads `userEarnedReward` You should grant the reward only when the event occurs. `dismissed`By itself, you can't tell whether the user watched the ad all the way through.

### Example code

```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(
            "Reward earned:",
            event.data.unitType,
            event.data.unitAmount,
          );
          break;
        case "dismissed":
          console.log("The ad was closed.");
          cleanup();
          break;
        case "failedToShow":
          console.error("Failed to show the ad.");
          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-en/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.
