Forked from https://github.com/ratson/cordova-plugin-admob-free - Rona Dini Hari (rona.dinihari@gmail.com)
Cordova AdMob Plugin
A free, no ad-sharing version of Google AdMob plugin for Cordova.
Features
Compare to other projects
Click ❌ to see the detail.
Installation
cordova plugin add cordova-plugin-admob-free --save
Usage
1. Ceate Ad Unit ID for your banner and interstitial.
Go to AdMob portal, click "Monetize a new app" button to create new ad unit.
2. Define configiration for differrent platforms.
var admobid = {};
if ( /(android)/i.test(navigator.userAgent) ) {
admobid = {
banner: 'ca-app-pub-xxx/xxx',
interstitial: 'ca-app-pub-xxx/xxx',
};
} else if ( /(ipod|iphone|ipad)/i.test(navigator.userAgent) ) {
admobid = {
banner: 'ca-app-pub-xxx/xxx',
interstitial: 'ca-app-pub-xxx/xxx',
};
} else {
admobid = {
banner: 'ca-app-pub-xxx/xxx',
interstitial: 'ca-app-pub-xxx/xxx',
};
}
3. Set options
AdMob.setOptions({
publisherId: admobid.banner,
interstitialAdId: admobid.interstitial,
bannerAtTop: false,
overlap: true,
offsetTopBar: false,
isTesting: false,
autoShow: false,
});
4. Display advertisements
Banner Ad
AdMob.createBannerView();
AdMob.destroyBannerView();
AdMob.showAd(false);
AdMob.showAd(true);
Interstitial Ad
AdMob.prepareInterstitial({
interstitialId: admobid.interstitial,
autoShow: false,
});
AdMob.showInterstitial();
5. Profit
Screenshots
Android Banner | Android Interstitial |
---|
| |
iPhone Banner | iPhone Interstitial |
---|
| |
API
Methods:
AdMob.setOptions(options, success, fail);
AdMob.createBannerView();
AdMob.destroyBannerView();
AdMob.showAd();
AdMob.prepareInterstitial(adId/options, success, fail);
AdMob.showInterstitial();
AdMob.createInterstitialView();
AdMob.requestInterstitialAd();
AdMob.showInterstitialAd();
Events:
document.addEventListener('onReceiveAd', function() {});
document.addEventListener('onFailedToReceiveAd', function(data) {});
document.addEventListener('onPresentAd', function() {});
document.addEventListener('onDismissAd', function() {});
document.addEventListener('onLeaveToAd', function() {});
document.addEventListener('onReceiveInterstitialAd', function() {});
document.addEventListener('onPresentInterstitialAd', function() {});
document.addEventListener('onDismissInterstitialAd', function() {});
Status
This plugin is forked from cordova-plugin-admob-simple and removed the ad-sharing related code. All APIs are remaining the same as the original fork.
For Android, there are also some enhanced options. If anyone wants them on iOS, please open an issue and let me know.
If you find this plugin useful, please star it on Github.
Contributing
You can use this Cordova plugin for free. You can contribute to this project in many ways:
Help with documentation is always appreciated and can be done via pull requests.
Credits
Thanks for the cordova-plugin-admob-simple author for forking the original project cordova-plugin-admob to make it functional and open source it.
Screenshots are copied from cordova-admob-pro.
Disclaimer
This is NOT an official Google product. It is just a community-driven project, which use the Google AdMob SDKs.
License
MIT