Cordova/PhoneGap Plugin for Facebook Audience Network Ads
Liming Xie3.21.12
platforms: android,ios
$ cordova plugin add com.rjfun.cordova.facebookads

Cordova Plugin for Facebook Audience Network

Present Facebook Ads in Mobile App/Games natively from JavaScript.


  • Easy-to-use APIs. Display Ad with single line of Js code.
  • Support Banner, Interstitial Ad, and Native Ad.
  • One plugin supports both Android and iOS platform.
  • Fixed and overlapped mode.
  • Auto fit on orientation change.
  • Actively maintained, prompt support.

Compatible with:

  • Cordova CLI, v3.5+
  • Intel XDK and Crosswalk, r1095+
  • IBM Worklight, v6.2+

How to use?

If use with Cordova CLI:

cordova plugin add com.rjfun.cordova.facebookads

If use with Intel XDK: Project -> CORDOVA 3.X HYBRID MOBILE APP SETTINGS -> PLUGINS AND PERMISSIONS -> Third-Party Plugins -> Add a Third-Party Plugin -> Get Plugin from the Web, input:

Name: FacebookAdsPluginPro
Plugin ID: com.rjfun.cordova.facebookads
[x] Plugin is located in the Apache Cordova Plugins Registry

Quick Start Example Code

Step 1: Prepare your Facebook Audience Network Placement Id for your app, create it in Facebook Developers website

var ad_units = {
    ios : { 
    android : {

// select the right Ad Id according to platform
var adid = (/(android)/i.test(navigator.userAgent)) ? ad_units.android : ad_units.ios;

// set your hashed device id if testing on device (optional)
if(FacebookAds) FacebookAds.setOptions({
    isTesting: true,
    deviceHash: 'copy_your_hash_id_from_console_here'

Step 2: Create a banner with single line of javascript

// it will display smart banner at top center, using the default options
if(FacebookAds) FacebookAds.createBanner( adid.banner );

Or, show the banner Ad in some other way:

// or, show a default banner at bottom
if(FacebookAds) FacebookAds.createBanner( {
    adId: adid.banner, 
    autoShow:true} );

Step 3: Prepare an interstitial, and show it when needed

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

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

You can even embed the Ad into web content with Native Ad.

Check the example code test/index.html

Javascript API Overview


// set default value for other methods
setOptions(options, success, fail);
// for banner
createBanner(adId/options, success, fail);
showBannerAtXY(x, y);
// for interstitial
prepareInterstitial(adId/options, success, fail);
// for native ad
createNativeAd(adId, success, fail);

Detailed Documentation

The APIs, Events and Options are detailed documented.

Read the detailed API Reference Documentation English.


If encounter problem when using the plugin, please read the FAQ first.

Full Example Code

This FacebookAds Plugin Pro offers the most flexibility and many options.

Check the test/index.html.


iPhone Banner iPhone Interstitial
ScreenShot ScreenShot

iPhone Landscape


iPhone Native Ad Android Native Ad
ScreenShot ScreenShot

Ad PluginPro series for the world leading Mobile Ad services:

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

If use in commercial project or need prompt support, please buy a license, you will be served with high priority.

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