# AdMob

{% hint style="info" %}
You'll need to import the javascript file in your website before starting from this [link](https://docs.webtonative.com/javascript-apis/getting-started).
{% 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

***

### 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
