Plugin Documentation

Add advertising to your native Android and iOS game.

Usage

This plugin uses Google AdMob ad network. To get started, you need to create an AdMob account and register an app.

Configure

After you have registered your app, copy it's App ID to your game.config

game.config = {
    mobileAds: {
        appId: 'ca-app-pub-3940256099942544~3347511713'
    }
};

Android and iOS versions will have different App ID's, you can easily define them both in your game.config

game.config = {
    android: {
        mobileAds: {
            appId: 'ca-app-pub-3940256099942544~3347511713'
        }
    },

    iOS: {
        mobileAds: {
            appId: 'ca-app-pub-3940256099942544~1458002511'
        }
    }
};

Now you can start showing ads.

First you need to define ad unit ID of your banner ad on your game.config

game.config = {
    bannerAd: {
        adUnitId: 'ca-app-pub-3940256099942544/6300978111'
    }
};

Load banner ad by creating new instance of BannerAd class.

var banner = new game.BannerAd();

Then show it to user with show function.

banner.show();

You can hide banner with hide function.

banner.hide();

Both show and hide will take function as a parameter, which gets called when the operation is completed.

banner.show(function() {
    // Banner is showed
});

You can also customize banner size and position. By default, banner size is smart banner and positioned on bottom of the screen.

banner.position = 'TOP';
banner.size = 'BANNER';

See all available sizes here.

Interstitial

First you need to define ad unit ID of your interstitial ad on your game.config

game.config = {
    interstitialAd: {
        adUnitId: 'ca-app-pub-3940256099942544/1033173712'
    }
};

Load interstitial ad by creating new instance of InterstitialAd class.

var interstitial = new game.InterstitialAd();

Start loading it with load function.

interstitial.load();

Once the ad is loaded, onReady function will be called. It's good idea to define this before loading the ad.

interstitial.onReady = function(error) {
    // Interstitial ad loaded
};

If there is any error while loading the ad, onReady function will be called with the error message as a parameter.

You can show the ad with show function, this can be only called after the ad is loaded.

interstitial.show();

show function will take a function as a parameter, which will be called after user has closed the ad.

interstitial.show(function() {
    // User closed the ad
});

Full example of interstitial ad:

var interstitial = new game.InterstitialAd();
interstitial.onReady = function() {
    interstitial.show();
};
interstitial.load();

Rewarded Video

Rewarded video ad works pretty much same way as the interstitial ad. First define add unit id:

game.config = {
    rewardedVideoAd: {
        adUnitId: 'ca-app-pub-3940256099942544/5224354917'
    }
};

Then use RewardedVideoAd class with same functions as with InterstitialAd.

var rewarded = new game.RewardedVideoAd();
rewarded.onReady = function() {
    rewarded.show();
};
rewarded.load();

show function will take function as a parameter, which gets called after the rewarded video ad is closed. The function will have object as a parameter, which contains all the info about the reward.

rewarded.show(function(reward) {
    var type = reward.type;
    var amount = reward.amount;
    console.log('You got rewarded ' + amount + ' ' + type);
});

Example

Plugin contains example project that will show you how to setup all ads for both Android and iOS platforms in a single project.