Help intergrated facebook audience into facebook instant game

Hi all,

I am trying to integrate facebook ads into facebook instant game. I search in forum but I don’t see any tutorials about it. Can anyone help to show me a tutorial about it?

For my investigate. I try to put facebook ads example from facebook demo but it not work. Can anyone help me show my errors. Below is my code.

In main.js:

(function () {

'use strict';
	const INTERSTITIAL_PLACEMENT_ID = '2060729547504307_2060751777502084';
	const REWARDED_PLACEMENT_ID = '2060729547504307_2061634247413837';

	var watchedInterstitials = 0;
	var watchedRewardedVideos = 0;
	var preloadedRewardedVideo = null;
	var preloadedInterstitial = null;
function boot () {


}
function showInterstitial() {
preloadedInterstitial.showAsync()
.then(function() {
// Perform post-ad success operation
// displayInterstitialAmount(++watchedInterstitials);
})
.catch(function(e) {
// displayError(e.message);
});
}
if (window.document) {

    var cocos2d = document.createElement('script');
    cocos2d.async = true;
    cocos2d.src = window._CCSettings.debug ? 'cocos2d-js.js' : 'cocos2d-js-min.js';

    var engineLoaded = function () {
        FBInstant.initializeAsync()
            .then(function () {
                document.body.removeChild(cocos2d);
                cocos2d.removeEventListener('load', engineLoaded, false);
                window.eruda && eruda.init() && eruda.get('console').config.set('displayUnenumerable', false);
                boot();
				var supportedAPIs = FBInstant.getSupportedAPIs();
				if (supportedAPIs.includes('getInterstitialAdAsync') && supportedAPIs.includes('getRewardedVideoAsync')){
        //
        // Preload Interstitial
        //
				FBInstant.getInterstitialAdAsync(
					INTERSTITIAL_PLACEMENT_ID, // Your Ad Placement Id
					).then(function(interstitial) {
          // Load the Ad asynchronously
					preloadedInterstitial = interstitial;
						return preloadedInterstitial.loadAsync();
					}).then(function() {
					document.getElementById('btn-interstitial').style.visibility = 'visible';
					}).catch(function(err){
					// displayError('Interstitial failed to preload: ' + err.message);
					});
            });
    };
    cocos2d.addEventListener('load', engineLoaded, false);
	
	
    document.body.appendChild(cocos2d);
}

})();

2 Likes

I am also searching for that but not find any information regarding that. If any one have idea please share that how we able to integrate ads in facebook instant games using cocos creator.

1 Like

me too. Currently working on. Anyone found the solution

You do need to have your game reviewed by facebook in the facebook instant games dashboard. If you haven’t passed review then you can’t use ads.

1 Like

okay. So any links on cocos Creator ADs sdk implementation?

Hi @Tony_Ho can you guide me the process of Adding Ads sdk into cocos creator. I am stuck into it. need help.