Skip to content

Instantly share code, notes, and snippets.

@imelgrat
Last active February 15, 2019 15:43
Show Gist options
  • Save imelgrat/440fdc91af39a4372232d3709db5ef76 to your computer and use it in GitHub Desktop.
Save imelgrat/440fdc91af39a4372232d3709db5ef76 to your computer and use it in GitHub Desktop.
Configure AdMob ads on a Phonegap application
/**
* Create an AdMob banner ad using AdMob Plugin Pro (in Phohegap)
*
* @link https://imelgrat.me/phonegap/admob-effective-monetize-cordova-app/
*
* @link https://goo.gl/yTCAea AdMob Plugin Pro
*
*/
function createSelectedBanner()
{
AdMob.createBanner( { adId:admobid.banner,
bgColor: '#XXYYZZ', overlap:false,
adSize: 'SMART_BANNER',// Available sizes are SMART_BANNER, BANNER,MEDIUM_RECTANGLE,FULL_BANNER,LEADERBOARD and SKYSCRAPER
position:8 //1 => Top Left, 2 => Top Center, 3 => Top Right, 4 => Left, 5 => Center, 6 => Right, 7 => Bottom Left, 8 => Bottom Center, 9 => Bottom Right
});
}
/**
* Define the right AdMob ID according to mobile platform (Banner and Intersitial types)
*
* @link https://imelgrat.me/phonegap/admob-effective-monetize-cordova-app/
*
* @link https://goo.gl/yTCAea AdMob Plugin Pro
*
*/
var admobid = {};
if (/(android)/i.test(navigator.userAgent)) {
// for android
admobid = {
banner: "ca-app-pub-xxx/zzz", // or DFP format "/mmmmmmm/dfp_example_ad"
interstitial: "ca-app-pub-xxx/kkk"
};
} else if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)) {
// for ios
admobid = {
banner: "ca-app-pub-xxx/zzz", // or DFP format "/mmmmmmm/dfp_example_ad"
interstitial: "ca-app-pub-xxx/kkk"
};
} else {
// for windows phone
admobid = {
banner: "ca-app-pub-xxx/zzz", // or DFP format "/mmmmmmm/dfp_example_ad"
interstitial: "ca-app-pub-xxx/kkk"
};
}
/**
* Create an AdMob intersitial ad using AdMob Plugin Pro (in Phohegap)
*
* @link https://imelgrat.me/phonegap/admob-effective-monetize-cordova-app/
*
* @link https://goo.gl/yTCAea AdMob Plugin Pro
*
*/
function prepareInterstitial()
{
AdMob.prepareInterstitial({ adId:admobid.interstitial, autoShow:true });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment