Cordova AdMob Plugin

Cordova Admob Plugin

Monetize your Cordova/Phonegap/XDK HTML5 hybrid apps and games with AdMob ads, using latest Google AdMob SDK.

Get started with Cordova Admob Plugin…..

  • Now available with Ionic Native too
  • Supports banner, interstitials and rewarded
  • Optional Tappx backfill

With this Cordova/Phonegap/XDK plugin you can show AdMob ads as easy as:

admob.createBannerView({publisherId: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB"});

integrate admob with cordova app

Plugin update (phonegap/cordova cli)

cordova-admob~4.1.15 and later are now updated to latest SDK’s (ios 7.13.1 and later, android managed by gradle)

To update the plugin you should remove the plugin and add it again:

$ cordova plugin rm cordova-admob
$ npm cache clear
$ cordova plugin add cordova-admob

Sometimes removing the plugin causes an error (it’s been reported to cordova https://issues.apache.org/jira/browse/CB-12083). If that happens, remove first cordova-libgoogleadmobads manually:

$ rm plugins/cordova-libgoogleadmobads/ -rf
$ cordova plugin rm cordova-admob
$ npm cache clear
$ cordova plugin add cordova-admob

Quick start

To install this plugin, follow the Command-line Interface Guide. You can use one of the following command lines:

  • cordova plugin add cordova-admob
  • cordova plugin add https://github.com/appfeel/admob-google-cordova.git

To use in Phonegap Build, place the following tag in your config.xml file:

<gap:plugin name="phonegap-admob" source="npm"/>

To start showing ads, place the following code in your onDeviceReady callback. Replace corresponding id’s with yours:

Note: ensure you have a proper AdMob and tappx accounts and get your publisher id’s.

function onDeviceReady() {

      document.removeEventListener('deviceready', onDeviceReady, false);

      

      // Set AdMobAds options:

      admob.setOptions({

        publisherId:           "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB",  // Required

        interstitialAdId:      "ca-app-pub-XXXXXXXXXXXXXXXX/IIIIIIIIII",  // Optional

        autoShowBanner:        true,                                      // Optional

        autoShowRInterstitial: false,                                     // Optional

        autoShowRewarded:      false,                                     // Optional

        tappxIdiOS:            "/XXXXXXXXX/Pub-XXXX-iOS-IIII",            // Optional

        tappxIdAndroid:        "/XXXXXXXXX/Pub-XXXX-Android-AAAA",        // Optional

        tappxShare:            0.5                                        // Optional

      });

      

      // Start showing banners (atomatic when autoShowBanner is set to true)

      admob.createBannerView();

      

      // Request interstitial ad (will present automatically when autoShowInterstitial is set to true)

      admob.requestInterstitialAd();

 

      // Request rewarded ad (will present automatically when autoShowRewarded is set to true)

      admob.requestRewardedAd();

    }

    

    document.addEventListener("deviceready", onDeviceReady, false);

If you don’t specify tappxId, no tappx requests will be placed (even if you specify a tappxShare). See Tappx configuration for more detailed info.

⚠️ Be sure to start ads on “deviceready” event otherwise, the plugin would not work.

Leave a Reply

Your email address will not be published. Required fields are marked *