cordova-plugin-ads
Version:
Cordova plugin to add ads into an app. Use javascript to request ads by AdMob.
105 lines (84 loc) • 3.38 kB
Markdown
Banner advertisements which display at the bottom of the app screen.
jump to: [banner](
<hr/>
<p align="center">
<img src="banner.png" alt="banner ad" width="300" align="center" />
</p>
```js
adMob.banner(banner_id,adMob.ad_sizes.RESIZE,adMob.ad_positions.BOTTOM).then(function () {
// do anything after banner has loaded successfully
}).catch (function(err){
// view or handle error messages
});
```
- show a banner ad at the top or bottom of the app screen
- by default the ad size is "banner", 320x50, and the ad position is at the bottom of the screen
- use after the start up of the device (`onDeviceReady`)
## Parameters:
- `Google AdMob id` - for a banner ad <br>
can be `"test"` for test ads, or normally an ad string (`"ca-app-pub-4029587076166791/6431168058"`), or an ad_id object:
```
var admob_ids = {
'android' : {
'banner': "ca-app-pub-4029587076166791/6431168058",
'interstitial': "ca-app-pub-4029587076166791/1370413062",
'rewarded': "ca-app-pub-4029587076166791/9712771663",
'rewardedInterstitial': "ca-app-pub-4029587076166791/3530506691"
}, 'ios' : {
'banner': "ca-app-pub-4029587076166791/6694891931",
'interstitial': "ca-app-pub-4029587076166791/2436352227",
'rewarded': "ca-app-pub-4029587076166791/5286441495",
'rewardedInterstitial': "ca-app-pub-4029587076166791/2300620853"
}
};
```
- `ad_size` (optional - select a banner size, default is BANNER)` <br>
- `adMob.ad_sizes.RESIZE` resizes to the get the largest fitting available banner
- `adMob.ad_sizes.BANNER` default 320x50 ad banner
- `adMob.ad_sizes.LARGE_BANNER` 300x100 (overlaps with UI on Android)
- `adMob.ad_sizes.MEDIUM_RECTANGLE` 300x250 (overlaps with UI on Android)
- `adMob.ad_sizes.FULL_BANNER` 468x60
- `adMob.ad_sizes.LEADERBOARD` 728x90
- `ad_position` (optional - select a banner position, default is BOTTOM)` <br>
- `adMob.ad_positions.BOTTOM` default
- `adMob.ad_positions.TOP`
```
- error["description"] //short description about where the error is coming from
- error["name"] //name of the error (LOAD_AD_ERROR, SHOW_AD_ERROR, INVALID_ARGUMENTS, etc.)
- error["message"] //error message, more information about the error
- error["responseCode"] //ad error response code from Google (if there is one)
- error["responseMessage"] //ad error response message from Google (if there is one)
```
common error names: <br>
- `LOAD_AD_ERROR` may occur when an ad id is not reconized or not ready to show ads yet
- call this again if it fails
```js
adMob.removeBanner().then(function () {
// do anything after banners were removed
}).catch (function(err){
// view or handle error messages (uncommon)
});
```
- remove the banner ad
- use after a call to banner if you wish to remove it
- none needed
```js
function onDeviceReady() {
adMob.banner(banner_id,adMob.ad_sizes.RESIZE).catch(function(err){});
}
```
<hr/>
<p align="center">
[](../README.md
</p>