/cordova-admob-pro

Powerful Ad Plugin for Google AdMob and DFP. Easy use, show mobile Ad with single line of JavaScript. Stable and up to date with latest SDK. Compatible with Cordova CLI, PhoneGap Build, Intel XDK/Crosswalk, Google ChromeApp, IBM Worklight.

Primary LanguageObjective-CMIT LicenseMIT

AdMob Plugin Pro

Cordova / PhoneGap Plugin for Google Ads, including AdMob / DFP (doubleclick for publisher) and mediations to other Ad networks.

Contents

  1. Description
  2. History
  3. Features
  4. Demo
  5. Quick Start
  6. Installation
  7. Usage
  8. API
  9. Wiki and Docs
  10. Important Tips
  11. Video Tutorial
  12. Screenshots
  13. Credits

Description

This Cordova / PhoneGap plugin enables displaying mobile Ads with single line of javascript code. Designed for the use in HTML5-based cross-platform hybrid games and other applications.

History

Community-driven project. Designed and maintained by Raymond Xie since August 2014. It also features integration in AngularJS projects via [ngCordova] (http://www.ngcordova.com).

It was published to Cordova registry with id "com.google.cordova.admob" since Aug 2014, and has been downloaded more than 120,000 times. Now it's the No. 1 monetization plugin for Cordova community.

ScreenShot

From May 2015, Cordova team announced the deprecation of Cordova registry, and suggest all plugins to be moved to npm repository. Now, the AdMob plugin is published to npm and renamed as "cordova-plugin-admobpro".

Features

Platforms supported:

  • Android, via SDK v7.8 (part of Google Play service platform)
  • iOS, via SDK v7.5.0
  • Windows Phone, via SDK v6.5.13
  • Amazon-FireOS, via Android SDK (part of Google Play service platform)

Ad Types:

  • Banner
  • Interstitial (text, picture, video)
  • IAP Ad
  • Native Ad (Google new product, on roadmap)

Mediation to other Ad networks:

  • AdMob (built-in)
  • DFP (DoubleClick for Publisher, built-in)
  • Facebook Audience Network
  • Flurry
  • iAd
  • InMobi
  • Millennial Media
  • MobFox

Quick Demo

Wanna quickly see the mobile ad on your simulator or device? Try the following commands.

    # install cordova CLI
    [sudo] npm install cordova -g

    # install a small utility to run all the commands for you
    [sudo] npm install plugin-verify -g

    # Demo 1: run admob demo with sample index.html
    plugin-verify cordova-plugin-admobpro

    # Demo 2/3: run admob demo in game powered by PIXI/phaser HTML5 engine
    plugin-verify admob-demo-game-pixi ios --landscape
    plugin-verify admob-demo-game-phaser ios --landscape

    # Demo 4: run admob demo in app powered by ionic/angular framework
    plugin-verify admob-demo-app-ionic ios --portrait

Quick start

	# create a demo project
    cordova create test1 com.rjfun.test1 Test1
    cd test1
    cordova platform add android
    cordova platform add ios

    # now add the plugin, cordova CLI will handle dependency automatically
    cordova plugin add cordova-plugin-admobpro

    # now remove the default www content, copy the demo html file to www
    rm -r www/*;
    cp plugins/cordova-plugin-admobpro/test/* www/;

	# now build and run the demo in your device or emulator
    cordova prepare; 
    cordova run android; 
    cordova run ios;
    # or import into Xcode / eclipse

Installation

  • If use with Cordova CLI:
cordova plugin add cordova-plugin-admobpro

If use other tools or online build services, see:

What's difference of the 3 plugin IDs, which one shall I use ?

  • com.google.cordova.admob
  • cordova-plugin-admobpro
  • cordova-plugin-admob

Read: Difference of Plugin ID

Notice:

  • If build locally using cordova-plugin-admobpro, to avoid build error, you need install some extras in Android SDK manager (type android sdk to launch it): android extra

Usage

Show Mobile Ad with single line of javascript code.

Step 1: Create Ad Unit Id for your banner and interstitial, in AdMob portal, then write it in your javascript code.

// select the right Ad Id according to platform
    var admobid = {};
    if( /(android)/i.test(navigator.userAgent) ) { // for android & amazon-fireos
		admobid = {
			banner: 'ca-app-pub-xxx/xxx', // or DFP format "/6253334/dfp_example_ad"
			interstitial: 'ca-app-pub-xxx/yyy'
        };
    } else if(/(ipod|iphone|ipad)/i.test(navigator.userAgent)) { // for ios
		admobid = {
			banner: 'ca-app-pub-xxx/zzz', // or DFP format "/6253334/dfp_example_ad"
			interstitial: 'ca-app-pub-xxx/kkk'
		};
    } else { // for windows phone
		admobid = {
			banner: 'ca-app-pub-xxx/zzz', // or DFP format "/6253334/dfp_example_ad"
			interstitial: 'ca-app-pub-xxx/kkk'
		};
    }

Step 2: Want cheap and basic banner? single line of javascript code.

// it will display smart banner at top center, using the default options
if(AdMob) AdMob.createBanner( {
	adId: admobid.banner, 
	position: AdMob.AD_POSITION.TOP_CENTER, 
	autoShow: true } );

Step 3: Want interstitial Ad to earn more money ? Easy, 2 lines of code.

// preppare and load ad resource in background, e.g. at begining of game level
if(AdMob) AdMob.prepareInterstitial( {adId:admobid.interstitial, autoShow:false} );

// show the interstitial later, e.g. at end of game level
if(AdMob) AdMob.showInterstitial();

Or, you can just copy this admob_simple.js to your project, and ref in your index.html.

AdMob Mediation Adapters

Optional mediations to increase your revenue (Read about AdMob Mediation Networks):

cordova plugin add cordova-plugin-admob-facebook
cordova plugin add cordova-plugin-admob-flurry
cordova plugin add cordova-plugin-admob-iad
cordova plugin add cordova-plugin-admob-inmobi
cordova plugin add cordova-plugin-admob-mmedia
cordova plugin add cordova-plugin-admob-mobfox

Notice: If you want to add multiple mediations, please balance flexibility and binary size.

API

Methods:

// use banner
createBanner(adId/options, success, fail);
removeBanner();
showBanner(position);
showBannerAtXY(x, y);
hideBanner();

// use interstitial
prepareInterstitial(adId/options, success, fail);
showInterstitial();

// set default value for other methods
setOptions(options, success, fail);

Events:

// onAdLoaded
// onAdFailLoad
// onAdPresent
// onAdDismiss
// onAdLeaveApp
document.addEventListener('onAdFailLoad', function(e){
    // handle the event
});

Wiki and Docs

Quick start, simply copy & paste:

API Reference:

Other Documentations:

Demo projects:

Tips

Some important tips, FYI.

  • Strongly recommend Interstitial, more than 10 times profit than banner Ad.
Ad Format Banner Interstitial
Click Rate < 1% 3-15%
RPM (revenue per 1000 impression) US$ 0.5~4 US$ 10~100
  • RPM top countries (stat data in recent 2 months, FYI): ScreenShot

  • Using SMART_BANNER to auto-fit the screen width, avoid using BANNER or FULL_BANNER (unless you are using DFP)

  • Why Chooese Google AdMob ?

Advertisement is main business and income source of Google, so the clients are all around the world. Google is one of the most realable partners for its high quality service.

  • High fill rate, nearly 100% all around world.
  • High quality Ad, bring high RPM.
  • Stable price, auto pay on time. Pay on every 20th next month.

Video Tutorial

  • Using Cordova CLI to Add AdMob Plugin:

Video

  • Run AdMob Demo App on Android:

Video

Screenshots

iPhone Banner iPhone Interstitial
ScreenShot ScreenShot
Android Banner Android Interstitial
ScreenShot ScreenShot

Credits

This project is created and maintained by Raymond Xie.

More Cordova/PhoneGap plugins by Raymond Xie, find them in plugin registry, or find them in npm.

If use in commercial project and need email/skype support, please get a license, you will be supported with high priority.

Project outsourcing and consulting service is also available. Please contact us if you have the business needs.