Last active
June 8, 2016 21:04
-
-
Save Shuky/339fd382b2e0905e3947f625f78c6184 to your computer and use it in GitHub Desktop.
Facebook Audience Network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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