Skip to content

Instantly share code, notes, and snippets.

@Shuky
Last active June 8, 2016 21:04
Show Gist options
  • Select an option

  • Save Shuky/339fd382b2e0905e3947f625f78c6184 to your computer and use it in GitHub Desktop.

Select an option

Save Shuky/339fd382b2e0905e3947f625f78c6184 to your computer and use it in GitHub Desktop.
Facebook Audience Network
//creates a facebook ad html element on the dom
function createFacebookAdElement(placementId) {
var adElemWrap = document.createElement('div');
adElemWrap.innerHTML = '<div class="fb-ad center" data-format="300x250" data-placementid="'+placementId+' data-testmode="true"></div>'
document.body.appendChild(adElemWrap);
setTimeout(function() {
window.fbAsyncInit = function() {
FB.Event.subscribe('ad.loaded', function(placementID) {
console.log('fb -> loaded: ',placementID);
});
FB.Event.subscribe('ad.error', function(errorCode, errorMessage, placementID) {
console.log('fb -> ad error ' + errorCode + ': ' + errorMessage);
});
};
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = '//connect.facebook.net/en_US/sdk/xfbml.ad.js#xfbml=1&version=v2.5&appId=215946881864350';
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
}, 1000);
}
window.onload = function() {
var YOUR_PLACEMENT_ID = 12345;
createFacebookAdElement(YOUR_PLACEMENT_ID);
createFacebookAdElement(YOUR_PLACEMENT_ID);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment