> For the complete documentation index, see [llms.txt](https://docs.webtonative.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.webtonative.com/javascript-apis/admob.md).

# AdMob JavaScript API

Integrate Google AdMob into your app using the WebToNative JavaScript API. Display banner, interstitial, and rewarded ads with ease.

{% hint style="info" %}
You'll need to import the JavaScript file into your website before starting from this [link](https://docs.webtonative.com/javascript-apis/getting-started.md).
{% endhint %}

{% tabs %}
{% tab title="Plain Javascript" %}

```javascript
const {
    bannerAd,
    fullScreenAd,
    rewardsAd,
} = WTN.AdMob;

bannerAd({
  adId:"ca-app-pub-3940256099942544/6300978111"
})

fullScreenAd({
  adId:"ca-app-pub-3940256099942544/1033173712",
  fullScreenAdCallback: (value) => {
    console.log(value)
  }
})

rewardsAd({
  adId:"ca-app-pub-3940256099942544/5224354917",
  rewardsAdCallback: (value) => {
    console.log(value)
  }
})


/** Example for fullScreenAd
  fullScreenAd({
    adId:"ca-app-pub-3940256099942544/1033173712",
    fullScreenAdCallback: (value) => {
      console.log(value);
      try{
        let response = JSON.parse(value);
        let status = response.status;
        let error = response.error;
        let additionalData = response.additionalData;
        let rewardsData = response.rewardsData;
        // Your code to handle the values accordingly.
      }
      catch(e){
        console.log("JSON parse error : ",e);
      }
    }
  })
*/
```

{% endtab %}

{% tab title="ES5+" %}

```javascript
import {
  bannerAd,
  fullScreenAd,
  rewardsAd,
} from "webtonative/AdMob";

bannerAd({
  adId:"ca-app-pub-3940256099942544/6300978111"
})

fullScreenAd({
  adId:"ca-app-pub-3940256099942544/1033173712",
  fullScreenAdCallback: (value) => {
    console.log(value)
  }
})

rewardsAd({
  adId:"ca-app-pub-3940256099942544/5224354917",
  rewardsAdCallback: (value) => {
    console.log(value)
  }
})


/** Example for fullScreenAd
  fullScreenAd({
    adId:"ca-app-pub-3940256099942544/1033173712",
    fullScreenAdCallback: (value) => {
      console.log(value);
      try{
        let response = JSON.parse(value);
        let status = response.status;
        let error = response.error;
        let additionalData = response.additionalData;
        let rewardsData = response.rewardsData;
        // Your code to handle the values accordingly.
      }
      catch(e){
        console.log("JSON parse error : ",e);
      }
    }
  })
*/
```

{% endtab %}
{% endtabs %}

**bannerAd, fullScreenAd and rewardsAd** can be called for displaying the particular ad.

* **fullScreenAdCallback and rewardsAdCallback** - This callback function is called on successfully displaying the ad, when it is dismissed or in case of any error with values like **status, error, additionalData and rewardsData.**
* **status -** Values for status will be
  * "success" - When ad is shown successfully.
  * "adDismissed" - When ad is dismissed by user.
  * "adLoadFailure" - When ad could not be loaded.
  * "adError" - When ad could not be loaded on full screen.
  * "rewardSuccess" - When user completes the reward ad.

#### AdMob Ad Load Success/Failure Callback (Webtonative Configuration)

`window.admobLoadCallback` is called to report the success or failure of AdMob ads loaded via Webtonative configuration.

\*Taken Live on 19/12/25

***

### `rewardedInterstitialAd`

Loads an AdMob rewarded interstitial ad and shows it as soon as it is loaded. The user earns a reward for watching it, and can close it at any time.

#### Before you call it

AdMob requires an intro screen before every rewarded interstitial. Your page shows it, not the app. It must:

* say what the user gets for watching (for example, "Watch an ad to earn 10 coins")
* give the user a clear way to skip the ad (a **Skip** button)
* Important: If these requirements are not implemented, your app may violate AdMob's policies. This could result in ad-serving restrictions, suspension of your AdMob account, or disruption of your advertising system.

Please ensure these requirements are properly implemented before calling the Rewarded Interstitial Ad.

Call `rewardedInterstitialAd` only when the user doesn't skip. Never call it on page load or without the intro screen.

#### Syntax

```js
window.WTN.AdMob.rewardedInterstitialAd({
  adId: "ca-app-pub-xxxxxxxxxxxxxxxx/yyyyyyyyyy",
  rewardedInterstitialAdCallback: function (data) {
    console.log(data);
  }
});
```

| Parameter                        | Type     | Required | Description                                                                                                                                     |
| -------------------------------- | -------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| `adId`                           | String   | Yes      | Ad unit ID of a **Rewarded interstitial** ad unit from your AdMob account. Other ad unit formats (Rewarded, Interstitial, Native) fail to load. |
| `rewardedInterstitialAdCallback` | Function | No       | Receives each response object (already parsed). It is called several times for one ad.                                                          |

#### Example

```js
function watchAdForCoins() {
  // 1. Your intro screen: reward message + Skip. Call this only if the user doesn't skip.
  window.WTN.AdMob.rewardedInterstitialAd({
    adId: "ca-app-pub-xxxxxxxxxxxxxxxx/yyyyyyyyyy",
    rewardedInterstitialAdCallback: function (data) {
      switch (data.status) {
        case "success":       // ad is showing
          break;
        case "rewardSuccess": // user earned the reward: give it here, only once
          break;
        case "adDismissed":   // ad closed: continue the user's flow
          break;
        case "adLoadError":   // Android: ad failed to load
        case "adError":       // iOS: failed to load or show. Android: failed to show
        case "adLoadFailure": // Android: ad was not ready
          break;
      }
    }
  });
}
```

#### Callback responses

`adType` is always `"REWARDED_INTERSTITIAL_ADMOB"`. iOS also sends `type` with the same value.

A normal ad sends, in order: `success` → `rewardSuccess` (only if the user watched long enough) → `adDismissed`.

**Ad is showing** (Android and iOS)

```json
{ "status": "success", "adType": "REWARDED_INTERSTITIAL_ADMOB" }
```

**Reward earned** (Android)

```json
{ "status": "rewardSuccess", "rewardData": { "type": "<reward type>", "amount": 10 }, "adType": "REWARDED_INTERSTITIAL_ADMOB" }
```

`rewardData` holds the reward type and amount set on the ad unit in AdMob.

**Reward earned** (iOS)

```json
{ "type": "REWARDED_INTERSTITIAL_ADMOB", "status": "rewardSuccess", "adType": "REWARDED_INTERSTITIAL_ADMOB" }
```

iOS does not send `rewardData`. Use the reward your page offered on the intro screen.

**Ad closed** (Android and iOS)

```json
{ "status": "adDismissed", "adType": "REWARDED_INTERSTITIAL_ADMOB" }
```

**Failed to load** (Android)

```json
{
  "status": "adLoadError",
  "error": { "message": "<error message>", "code": <error code>, "domain": "com.google.android.gms.ads" },
  "adType": "REWARDED_INTERSTITIAL_ADMOB"
}
```

**Failed to load** (iOS)

```json
{ "type": "REWARDED_INTERSTITIAL_ADMOB", "status": "adError", "error": "<error message>", "adType": "REWARDED_INTERSTITIAL_ADMOB" }
```

**Failed to show** (Android)

```json
{ "status": "adError", "error": { "message": "<error message>", "code": <error code>, "domain": "com.google.android.gms.ads" }, "adType": "REWARDED_INTERSTITIAL_ADMOB" }
```

**Failed to show** (iOS)

```json
{ "type": "REWARDED_INTERSTITIAL_ADMOB", "status": "adError", "error": "<error message>", "adType": "REWARDED_INTERSTITIAL_ADMOB" }
```

**Ad was not ready** (Android only, rare)

```json
{ "status": "adLoadFailure", "adType": "REWARDED_INTERSTITIAL_ADMOB" }
```

On Android, `error` is an object. On iOS, it is a string.

#### Notes

* **Give the reward once.** Give it only on `rewardSuccess` in `rewardedInterstitialAdCallback`. The app also sends every response to `window.admobLoadCallback` (if your page defines it), so don't count the reward there as well.
* **One AdMob full-screen ad at a time.** `fullScreenAd`, `rewardsAd` and `rewardedInterstitialAd` share one callback. If you start another one before this ad finishes, the newer call's callback gets the responses.
* **When the callback stops.** It is removed after `adDismissed`, `adLoadError` or `adError`.
* **Test ad units.** Use Google's test IDs while testing. Clicking your own live ads can get your AdMob account limited.

| Platform | Test ad unit ID                          |
| -------- | ---------------------------------------- |
| Android  | `ca-app-pub-3940256099942544/5354046379` |
| iOS      | `ca-app-pub-3940256099942544/6978759866` |

***

### AdMob UMP (GDPR Consent)

The following functions allow you to integrate Google's User Messaging Platform (UMP) for handling user consent as required by GDPR and other regional privacy regulations. Use these before loading ads to ensure compliance.

***

#### Request AdMob Consent

Requests the AdMob User Consent form from Google's User Messaging Platform (UMP).

If consent is required for the user (for example due to GDPR or regional privacy regulations), the consent screen will automatically appear. If consent is already obtained or not required for the user's region, the form will not be shown and the SDK will return the current consent status.

Use this method before loading ads to ensure compliance with privacy regulations.

```javascript
WTN.AdMob.requestAdmobConsent({ callback: (value) => {} });

// Response
{
  "type": "requestAdmobConsent",
  "status": "notRequired", // "obtained", "required", "unknown"
  "canRequestAds": true / false,

  // if got any error
  "error": "error_string"
}
```

**Response Fields**

| Field           | Type    | Description                                                                  |
| --------------- | ------- | ---------------------------------------------------------------------------- |
| `type`          | String  | Always `"requestAdmobConsent"`                                               |
| `status`        | String  | Consent status — `"notRequired"`, `"obtained"`, `"required"`, or `"unknown"` |
| `canRequestAds` | Boolean | Whether the app is allowed to request ads                                    |
| `error`         | String  | Error message, present only if an error occurred                             |

***

#### Check AdMob Consent Status

Checks the current AdMob consent status **without** displaying the consent form.

This method is useful when you only want to verify whether consent has already been obtained or is required before requesting ads. It returns the current consent status and whether the app is allowed to request ads.

```javascript
WTN.AdMob.checkAdmobConsentStatus({ callback: (value) => {} });

// Response
{
  "type": "checkAdmobConsentStatus",
  "status": "notRequired", // "obtained", "required", "unknown"
  "canRequestAds": true / false,

  // if got any error
  "error": "error_string"
}
```

**Response Fields**

| Field           | Type    | Description                                                                  |
| --------------- | ------- | ---------------------------------------------------------------------------- |
| `type`          | String  | Always `"checkAdmobConsentStatus"`                                           |
| `status`        | String  | Consent status — `"notRequired"`, `"obtained"`, `"required"`, or `"unknown"` |
| `canRequestAds` | Boolean | Whether the app is allowed to request ads                                    |
| `error`         | String  | Error message, present only if an error occurred                             |

***

#### Request AdMob Privacy Form

Displays the AdMob Privacy Options form provided by Google's User Messaging Platform.

This form allows users to review and modify their privacy and consent choices at any time, as required by GDPR and other privacy regulations. If the privacy form is not required for the user, it will not be shown and the current status will be returned.

```javascript
WTN.AdMob.requestAdmobPrivacyForm({ callback: (value) => {} });

// Response
{
  "type": "requestAdmobPrivacyForm",
  "status": "notRequired", // "required", "unknown"
  "canRequestAds": true / false,

  // if got any error
  "error": "error_string"
}
```

**Response Fields**

| Field           | Type    | Description                                                         |
| --------------- | ------- | ------------------------------------------------------------------- |
| `type`          | String  | Always `"requestAdmobPrivacyForm"`                                  |
| `status`        | String  | Privacy form status — `"notRequired"`, `"required"`, or `"unknown"` |
| `canRequestAds` | Boolean | Whether the app is allowed to request ads                           |
| `error`         | String  | Error message, present only if an error occurred                    |

***

#### Check AdMob Privacy Form Required

Checks whether the AdMob Privacy Options form needs to be shown to the user.

This does **not** display the form. It only returns the requirement status so the website can decide whether to provide a privacy options button or trigger the form later.

```javascript
WTN.AdMob.checkAdmobPrivacyFormRequired({ callback: (value) => {} });

// Response
{
  "type": "checkAdmobPrivacyFormRequired",
  "status": "notRequired", // "required", "unknown"
  "canRequestAds": true / false,

  // if got any error
  "error": "error_string"
}
```

**Response Fields**

| Field           | Type    | Description                                                         |
| --------------- | ------- | ------------------------------------------------------------------- |
| `type`          | String  | Always `"checkAdmobPrivacyFormRequired"`                            |
| `status`        | String  | Privacy form status — `"notRequired"`, `"required"`, or `"unknown"` |
| `canRequestAds` | Boolean | Whether the app is allowed to request ads                           |
| `error`         | String  | Error message, present only if an error occurred                    |

***

#### Recommended Usage Flow

{% stepper %}
{% step %}
On app start, call `requestAdmobConsent` to handle consent automatically before loading any ads.
{% endstep %}

{% step %}
Use `checkAdmobConsentStatus` if you need to verify consent state without prompting the user.
{% endstep %}

{% step %}
Provide a "Privacy Settings" button in your app that calls `requestAdmobPrivacyForm` so users can update their choices anytime.
{% endstep %}

{% step %}
Use `checkAdmobPrivacyFormRequired` to conditionally show or hide the privacy settings button.
{% endstep %}
{% endstepper %}

Feature taken live on Android and iOS on 16/03/2026
