Coder Social home page Coder Social logo

kanishkkunal / cordova-plugin-admob Goto Github PK

View Code? Open in Web Editor NEW

This project forked from alcschultz/cordova-plugin-admob

0.0 2.0 0.0 13.82 MB

AdMob Plugin for Cordova/PhoneGap, support Android, iOS and Windows Phone. Monetize your Cordova apps/games.

License: MIT License

Java 28.56% Objective-C 24.80% C# 38.23% JavaScript 8.41%

cordova-plugin-admob's Introduction

cordova-plugin-admob

AdMob Cordova Plugin, provides a way to request AdMob ads natively from JavaScript.

Platform SDK supported

  • iOS, using AdMob SDK for iOS, v6.12.0
  • Android, using Google Play Service for Android, r19
  • Windows Phone, using AdMob SDK for Windows Phone 8, v6.5.13

How to use?

To install this plugin, follow the Command-line Interface Guide.

cordova plugin add https://github.com/floatinghotpot/cordova-plugin-admob.git

Or,

cordova plugin add com.rjfun.cordova.plugin.admob

Note: ensure you have a proper AdMob account and create an Id for your app.

Quick example with cordova CLI

    cordova create <project_folder> com.<company_name>.<app_name> <AppName>
    cd <project_folder>
    cordova platform add android
    cordova platform add ios

    // cordova will handle dependency automatically
    cordova plugin add com.rjfun.cordova.plugin.admob

    // now remove the default www content, copy the demo html file to www
    rm -r www/*;
    cp plugins/com.rjfun.cordova.plugin.admob/test/index.html www/

    cordova prepare; cordova run android; cordova run ios;
    // or import into Xcode / eclipse

Javascript API

APIs:

setOptions(options, success, fail);

createBannerView(options, success, fail);
requestAd(options, success, fail);  // optional, will be absolete
showAd(true/false, success, fail); 
destroyBannerView();

createInterstitialView(options, success, fail);
requestInterstitialAd(options, success, fail); // optional, will be absolete
showInterstitialAd();

Example code

Call the following code inside onDeviceReady(), because only after device ready you will have the plugin working.

     function onDeviceReady() {
        initAd();

        // display a banner at startup
        window.plugins.AdMob.createBannerView();
        
        // prepare the interstitial
        window.plugins.AdMob.createInterstitialView();
        
        // somewhere else, show the interstital, not needed if set autoShow = true
        window.plugins.AdMob.showInterstitialAd();
    }
    function initAd(){
        if ( window.plugins && window.plugins.AdMob ) {
    	    var ad_units = {
				ios : {
					banner: 'ca-app-pub-xxx/4806197152',
					interstitial: 'ca-app-pub-xxx/7563979554'
				},
				android : {
					banner: 'ca-app-pub-xxx/9375997553',
					interstitial: 'ca-app-pub-xxx/1657046752'
				},
				wp8 : {
					banner: 'ca-app-pub-xxx/9375997559',
					interstitial: 'ca-app-pub-xxx/1657046759'
				}
    	    };
    	    var admobid = "";
    	    if( /(android)/i.test(navigator.userAgent) ) {
    	    	admobid = ad_units.android;
    	    } else if(/(iphone|ipad)/i.test(navigator.userAgent)) {
    	    	admobid = ad_units.ios;
    	    } else {
    	    	admobid = ad_units.wp8;
    	    }
            
            window.plugins.AdMob.setOptions( {
                publisherId: admobid.banner,
                interstitialAdId: admobid.interstitial,
                bannerAtTop: false, // set to true, to put banner at top
                overlap: false, // set to true, to allow banner overlap webview
                offsetTopBar: false, // set to true to avoid ios7 status bar overlap
                isTesting: false, // receiving test ad
                autoShow: true // auto show interstitial ad when loaded
            });

            registerAdEvents();
            
        } else {
            alert( 'admob plugin not ready' );
        }
    }
	// optional, in case respond to events
    function registerAdEvents() {
    	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(){ });
    }

See the working example code in demo under test folder, and here are some screenshots.

Screenshots (banner Ad / interstitial Ad)

iPhone:

ScreenShot

Credits

This plugin is mainly maintained by Raymond Xie, and also thanks to following contributors:

  • @jumin-zhu, added interstitial support for Android.
  • @fersingb, added interstitial support for iOS.
  • @AlexB71, improved WP8 support.
  • @ihshim523, added initial WP8 support.
  • And, bugfix patches from @chrisschaub, @jmelvin, @mbektchiev, @grahamkennery, @bastaware, @EddyVerbruggen, @codebykevin, @codebykevin, @zahhak.

You can use this plugin for FREE. To support the project, donation is welcome.

Forking and improving is welcome. Please ADD VALUE, instead of changing the name only.

See Also

Enhanced Cordova/PhoneGap plugins for the world leading Mobile Ad services:

AdMob Plugin Pro is highly recommended.

N-in-1 Advert Plugin for Cordova/PhoneGap. Maximize revenue with mediation to AdMob, DoubleClick, iAd, Flurry, Millennial Media, InMobi, Mobfox, and much more.

Highlights:

  • Easy-to-use: Can display Ad with single line of Js code.
  • Powerful: Support banner, interstitial, and video Ad.
  • Max revenue: Support mediation with up to 8 leading mobile Ad services.
  • Multi-size: Multiple banner size, also support custom size.
  • Flexible: Fixed and overlapped mode, put banner at any position with overlap mode.
  • Smart: Auto fit on orientation change.
  • Up to date: Latest SDK and Android Google play services.
  • Good support: Actively maintained, prompt response.

Tested with:

  • Cordova CLI, v3.0+ (do not use the buggy v3.4)
  • Intel XDK, r1095+
  • IBM Worklight, v6.2+

Mediation with:

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

News:

  • Recommended by Telerik in Verified Plugins Marketplace. read more ...
  • Recommended by William SerGio in code project (20 Jun 2014), read more ...
  • Recommended by Arne in Scirra Game Dev Forum (07 Aug, 2014), read more ...
  • Recommended by Intel XDK team (08/22/2014), read more ...

More plugins by Raymond Xie, click here.

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

cordova-plugin-admob's People

Contributors

chrisschaub avatar codebykevin avatar devadattas avatar eddyverbruggen avatar floatinghotpot avatar grahamkennery avatar hzlzh avatar ihshim523 avatar jmelvin avatar jperelli avatar junmin-zhu avatar muszek avatar vleango avatar vvelda avatar zahhak avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.