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);
}
})();