Adding ads to your Instant Game

You can monetize your game by showing ads. There are two types of ads available: Interstitial and Rewarded Video ads.

First make sure you have created your Facebook app with Instant Games first.

Audience Network

First you need to add Audience Network to your Facebook app.

Then create new ad placement.

Go to your just created ad placement and copy it's placement id.

Now your ad is ready to be used in Panda 2.

Configure

Next open your game project and insert the ad placement id into config.

game.config = {    
    instantAd: {
        // List of all Interstitial ad placement id's
        interstitial: [
            '149230679082759_152339552105205'
        ],
        // List of all Rewarded ad placement id's
        rewarded: [
        ]
    }
};

Now that your ad is configured, it will be automatically requested and loaded when the game is launched.

Showing ad

To show your ad, create new instance of InstantAd class and use your placement id as parameter. Then just load and show it using the code below.

game.createScene('Main', {
    init: function() {
        var ad = new game.InstantAd('149230679082759_152339552105205');
        ad.onReady = function(error) {
            ad.show();
        };
        ad.load();
    }
});

show function will have callback function as a paramter, which you can use to detect if the ad was displayed succesfully. For Rewarded Video ads, this function is called after the user finishes watching the video ad.

ad.show(function(error) {
    if (error) {
        // Error displaying ad
    }
    else {
        // Ad displayed correctly
    }
});

Testing

To try out the ad, upload your game and open it from mobile Messenger.

For more info about the InstantAd class, please take a look at the plugin documentation.