Monetizing your game with Audience Network

You can monetize your game by showing ads to your players. There are currently two formats of Audience Network ads integrated with Instant Games: Rewarded Videos and Interstitial Ads. This section will guide you through the process of integrating Ads Monetization with your Instant Game.

Prerequisites

  • You have configured Facebook Audience Network into your app.
  • You have created at least one Ad Placement.
  • You are able to test your builds on a mobile device (iOS or Android) since Audience Network ads cannot be requested by desktop browsers.

Please see the Audience Network Getting Started for more information. You can also refer to the Monetization Manager Help Center for help on how to create an ad placement.

Configure Facebook App

Download Sample

If you have already configured your app with Monetization Manager and have created your Ad Placements, you can see the sample code below in action by downloading our demo:

Download Ads Demo (.zip)

Showing an Interstitial Ad

The code snippet below shows an example of how to display an Interstitial Ad. For this code to work you will need to create an Ad Placement first.

Preload the ad

var preloadedInterstitial = null;

FBInstant.getInterstitialAdAsync(
  '123123123123_123123123123', // Your Ad Placement Id
).then(function(interstitial) {
  // Load the Ad asynchronously
  preloadedInterstitial = interstitial;
  return preloadedInterstitial.loadAsync();
}).then(function() {
  console.log('Interstitial preloaded')
}).catch(function(err){
  console.error('Interstitial failed to preload: ' + err.message);
});

Show the ad

preloadedInterstitial.showAsync()
.then(function() {
  // Perform post-ad success operation
  console.log('Interstitial ad finished successfully');        
})
.catch(function(e) {
  console.error(e.message);
});

Showing a Rewarded Video Ad

The code snippet below shows an example of how to display a Rewarded Video Ad. For this code to work you will need to create an Ad Placement first.

Preload the ad

var preloadedRewardedVideo = null;

FBInstant.getRewardedVideoAsync(
  '456456456456_456456456456', // Your Ad Placement Id
).then(function(rewarded) {
  // Load the Ad asynchronously
  preloadedRewardedVideo = rewarded;
  return preloadedRewardedVideo.loadAsync();
}).then(function() {
  console.log('Rewarded video preloaded')
}).catch(function(err){
  console.error('Rewarded video failed to preload: ' + err.message);
});

Show the ad

preloadedRewardedVideo.showAsync()
.then(function() {
  // Perform post-ad success operation
  console.log('Rewarded video watched successfully');        
})
.catch(function(e) {
  console.error(e.message);
});

Best practices and troubleshooting

The information below is specific to Instant Games. Please also refer to our guide Best Practices with Rewarded Video.

Preload ads: Don't wait until last minute to request, preload and show the ad the same time. Instead, make sure that you have some AdInstances preloaded, so that when the player requests to see it, they don't have to wait too much.

Check for support: In some cases, the player's session won't support ads - for instance if they are playing on the desktop browser. You should always check if ads are supported with FBInstant.getSupportedAPIs() before trying to request an ad.

Implement graceful handling of "No fills": Some conditions might cause the ad to not be filled. In that case, the promise will reject with an ADS_NO_FILL error message. Make sure that your game handles this gracefully and shows a friendly message.

Test your ads before submitting: As a developer of the app, you can request ads on mobile and see that your integration is working, even before you submit your app for Audience Network review.

Don't hold on to too many AdInstances: Both methods getRewardedVideoAsync or getInterstitialAdAsync return an AdInstance which can be preloaded. Preloading 3 or more AdInstances without showing them will cause subsequent attempts of creating a new AdInstance to fail. This means that calls to getRewardedVideoAsync and getInterstitialAdAsync will start to fail with error code ADS_TOO_MANY_INSTANCES until showAsync is called or until the player restarts Messenger.